Skip to content

Instantly share code, notes, and snippets.

@kimihito
Created July 9, 2012 17:32
Show Gist options
  • Save kimihito/3077790 to your computer and use it in GitHub Desktop.
Save kimihito/3077790 to your computer and use it in GitHub Desktop.
pacceptedstory bot
#!/usr/bin/env python
# coding: utf-8
import pivotal
import tweepy
from bs4 import BeautifulSoup
import datetime as d
from dateutil.parser import parse
import pytz
TOKEN = 'YOUR_TOKEN'
PROJECT_ID = 'PROJECT_ID'
pv = pivotal.Pivotal(TOKEN)
response, content = pv.projects(PROJECT_ID).stories(filter='state:accepted').get()
#get xml tags state accepted
soup = BeautifulSoup(content)
word = soup.findAll('name')
time = soup.findAll('accepted_at')
#pickup each name and accepted_at
times = []
for i in time:
times.append(parse(i.string))
words = []
for i in word:
j = i.string
words.append(j.replace('#gokidea',''))
#TODO accepted_time compere to now time.
#get now time
now = d.datetime.now(pytz.timezone('Asia/Tokyo'))
tweet = []
for i in zip(words,times):
n, t = i
if (now - t).total_seconds() <= 10 * 60:
tweet.append(n)
#tweet(accepted time and story name)
CONSUMER_KEY = "YOUR_CONSUMER_KEY"
CONSUMER_SECRET = "YOUR_SECRET_KEY
ACCESS_TOKEN = "YOUR_ACCESS_TOKEN"
ACCESS_TOKEN_SECRET = "YOUR_ACCESS_TOKEN_SECRET"
auth = tweepy.OAuthHandler(CONSUMER_KEY,CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth_handler = auth)
for i in tweet:
api.update_status(i + u"を完了しました")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment