Skip to content

Instantly share code, notes, and snippets.

View kdmgs110's full-sized avatar

Dai Kawai kdmgs110

View GitHub Profile
@kdmgs110
kdmgs110 / result.xml
Created October 21, 2017 06:36
Google Vision APIで取得したJSONデータをXML変換したもの
This file has been truncated, but you can view the full file.
<?xml version="1.0" encoding="utf-8"?>
<root>
<responses type="list">
<item type="dict">
<textAnnotations type="list">
<item type="dict">
<description type="str">
首都圏の公務員就職率の上位20位
設置
@kdmgs110
kdmgs110 / slack.py
Last active September 23, 2017 22:36
Slack.py
from selenium import webdriver
import time
import requests # for slack
import json # for slack
#Phanttomjs Driverを入手
browser = webdriver.PhantomJS('/usr/local/bin/phantomjs') # DO NOT FORGET to set path
#TODO set search query
@kdmgs110
kdmgs110 / dmm.py
Last active October 2, 2022 11:58
Twitterでエッチな投稿するプログラム
import urllib.request
from requests_oauthlib import OAuth1Session # ライブラリ(1)
from bs4 import BeautifulSoup
from TwitterAPI import TwitterAPI
import requests
import tweepy
import os
# 各種キーをセット
import numpy as np
'''
The following code is to help you play with Numpy, which is a library
that provides functions that are especially useful when you have to
work with large arrays and matrices of numeric data, like doing
matrix matrix multiplications. Also, Numpy is battle tested and
optimized so that it runs fast, much faster than if you were working
with Python lists directly.
'''
@kdmgs110
kdmgs110 / lln1.R
Last active August 5, 2017 09:21
大数法則1
#[1] 10回分試行する場合
n = 10
roll <- c("1","2","3","4","5","6") #サイコロの目を指定
sample(roll, n, replace=T) #sample関数(後述)
table(sample(roll, n, replace=T)) #サイコロの目を、100回振ったものをtableで表示
barplot(table(sample(roll, n, replace=T))) #それを棒グラフで表示
#[2] 100回試行する場合
n = 100
roll <- c("1","2","3","4","5","6") #サイコロの目を指定
import oauth
api = oauth.api
userid = "never_be_a_pm" #自分のツイッターアカウントのID
followers_id = api.followers_ids(userid) #自分のアカウントのフォロワーをすべて取得する
following_id = api.friends_ids(userid) #自分のアカウントのフォロイングをすべて取得する
for following in following_id: #自分がフォローしているユーザーだけ取得する
if following not in followers_id: #自分のフォローしているユーザーで、フォロワーに属さなユーザーを取得する 
userfollowers = api.get_user(following).followers_count
import oauth
api = oauth.api
#自分のタイムラインのツイートを取得
tweets = api.home_timeline(count = 30,include_rts = False)
#自分のタイムラインのツイートを30個取り出して、いいねする
for tweet in tweets:
try:
tweetid = tweet.id
import oauth
api = oauth.api
q = "http://review-of-my-life.blogspot.jp/*" #自分のブログのURL *は正規表現?で、これから下のものはすべてということ
count = 10 #取得するツイートの数
search_results = api.search(q=q, count=count)
for result in search_results:
username = result.user._json['screen_name']
user_id = result.id #ツイートのstatusオブジェクトから、ツイートidを取得
# Tweepyライブラリをインポート
import tweepy
# 各種キーをセット
CONSUMER_KEY = 'xxxxxxxx'
CONSUMER_SECRET = 'xxxxxxxx'
ACCESS_TOKEN = 'xxxxxxxx'
ACCESS_SECRET = 'xxxxxxxx'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
@kdmgs110
kdmgs110 / scraping.py
Created July 1, 2017 11:13
csv出力
# -*- coding: utf-8 -*-
from selenium import webdriver
from urllib.parse import urljoin
import time
import csv
import codecs
#Phanttomjs Driverを入手
browser = webdriver.PhantomJS()