Created
August 23, 2015 18:46
-
-
Save vim13/023d7caf4c6d43a95b51 to your computer and use it in GitHub Desktop.
ガキの使い番組内容tweet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python | |
#vim:fileencoding=utf-8 | |
import re | |
import time | |
import urllib2 | |
from pit import Pit | |
import tweepy | |
import BeautifulSoup | |
def parseHtml(uri): | |
my_uri = uri | |
html = urllib2.urlopen(my_uri).read() | |
soup = BeautifulSoup.BeautifulSoup(html) | |
return soup | |
def getId(soup): | |
article = soup('p')[1].string | |
ids = [article[i:i+140] for i in range(0, len(article), 140)] | |
ids.reverse() | |
return ids | |
def postTweet(ids, api): | |
for x in ids: | |
api.update_status(x.encode('utf-8')) | |
time.sleep(1) | |
if __name__ == '__main__': | |
key = Pit.get('twitter.com') | |
consumer_key = key['consumer_key'] | |
consumer_secret = key['consumer_secret'] | |
access_token = key['access_token'] | |
access_token_secret = key['access_token_secret'] | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_token, access_token_secret) | |
api = tweepy.API(auth) | |
uri = 'http://www.ntv.co.jp/gaki/oa.html' | |
soup = parseHtml(uri) | |
ids = getId(soup) | |
postTweet(ids, api) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment