Skip to content

Instantly share code, notes, and snippets.

@yanolab
Created September 4, 2012 06:13
Show Gist options
  • Save yanolab/3617486 to your computer and use it in GitHub Desktop.
Save yanolab/3617486 to your computer and use it in GitHub Desktop.
connpassからpyconjpの定員を取得して残数をツイートするスクリプト
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import re
import os
import sys
import lxml.html
import twitter
api = twitter.Api(
consumer_key = '********',
consumer_secret = '********',
access_token_key = '********',
access_token_secret = '********')
countfile = "count.now"
url = 'http://connpass.com/event/708/'
doc = lxml.html.parse(url)
match = re.match("\s*(\d+)/(\d+)", doc.xpath("//span[@class='entry']")[0].text)
if match:
now, max = map(int, match.groups())
if os.path.exists(countfile):
if now > int(open(countfile).read()):
with open(countfile, "w") as f: f.write(str(now))
else:
sys.exit(0)
else:
with open(countfile, "w") as f: f.write(str(now))
if now < max:
status = u"残り{0}人です!定員まで後わずか! #pyconjp".format(max - now)
api.PostUpdate(status=status)
elif now == max:
api.PostUpdate(status=u"定員に達しました!おめでとう! #pyconjp")
else:
print u"Error: connpassから定員を取得で来ませんでした。"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment