Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# coding: utf-8
import urllib,urllib2
from bs4 import BeautifulSoup
import serial
import datetime,time
def main():
ser = serial.Serial('ここにデバイス名',9600)
# コンテスト名,ユーザー名を入力
print "Contest Name: ",
contest_name = raw_input()
print "User Name: ",
user_name = raw_input()
url = 'http://' + contest_name +'.contest.atcoder.jp/submissions/all?user_screen_name=' + user_name
update_time = time.time()
while True:
print "update: " + str(datetime.datetime.now())
response = urllib2.urlopen(url)
# BeautifulSoupでhtmlをパース
soup = BeautifulSoup(response, "html5lib")
for cnt,tr in enumerate(soup.find_all("tr")):
# この辺は適当
if cnt == 0: continue
dt = ""
status = ""
for i,td in enumerate(tr.find_all('td')):
if i == 0:
dt = td.time.string
if i == 6:
status = td.span.string
if dt == "": continue
tm = datetime.datetime.strptime(dt[:-6],'%Y/%m/%d %H:%M:%S') + datetime.timedelta(hours=9)
tm = time.mktime(tm.timetuple())
# 新しい情報かつWaiting Judgeでないとき更新/Arduinoに送信
if update_time < tm and not ('/' in list(status) or status == 'WJ'):
update_time = tm
print status
if status == 'AC':
ser.write('a')
else:
ser.write('w')
time.sleep(5)
ser.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment