Created
October 3, 2011 12:54
-
-
Save alphaneet/1259034 to your computer and use it in GitHub Desktop.
gmailに体重送ったらgooからだログを更新します。gmailとgooのアカウントは捨て垢を推奨。つhttp://d.hatena.ne.jp/alpha_neet/20111003/1317650405
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
# -*- coding: utf-8 -*- | |
import sys | |
sys.path = ['mechanize-0.2.5'] + sys.path | |
import mechanize | |
import imaplib | |
import datetime | |
gmail_user = '自分のGmailのID' | |
gmail_pass = '自分のGmailのパスワード' | |
goo_user = '自分のgooのID' | |
goo_pass = '自分のgooのパスワード' | |
gmail = imaplib.IMAP4_SSL('imap.gmail.com') | |
gmail.login(gmail_user, gmail_pass) | |
gmail.select('Inbox') | |
nums = gmail.search(None, 'UNSEEN')[1][0].split() | |
for num in nums: | |
bodytext = gmail.fetch(num, "(BODY[TEXT])")[1][0][1] | |
try: | |
weight = str(float(bodytext)) | |
except Exception: | |
exit() | |
br = mechanize.Browser() | |
br.open('http://www.goo.ne.jp/') | |
br.open(br.find_link(text_regex='ログイン').url) | |
br.select_form(name='f1') | |
br['uname'] = goo_user | |
br['pass'] = goo_pass | |
br.submit() | |
gmtTime = datetime.datetime.utcnow() | |
jstTime = gmtTime + datetime.timedelta(hours=9) | |
br.open('http://karada.goo.ne.jp/diary/regist/' + jstTime.strftime('%Y%m%d')) | |
br.select_form(name='edit_form') | |
br['3'] = weight | |
br.submit() | |
br.select_form(name='regist') | |
br.submit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment