Last active
August 29, 2015 14:02
-
-
Save cocodrips/33d6601eca15d2331746 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import datetime | |
| import random | |
| import hashlib | |
| import base64 | |
| import requests | |
| USER_NAME = "" | |
| BLOG_ID = "ブログのURL" | |
| API_KEY = "ブログの詳細設定のとこにかいてあるやつ" | |
| def wsse(username, password): | |
| created = datetime.datetime.now().isoformat() + 'Z' | |
| nonce = hashlib.sha1(str(random.random())).digest() | |
| digest = hashlib.sha1(nonce + created + password).digest() | |
| return 'UsernameToken Username="{}", PasswordDigest="{}", Nonce="{}", Created="{}"'.format(username, base64.b64encode(digest), base64.b64encode(nonce), created) | |
| class Blog: | |
| headers = {'X-WSSE': wsse(USER_NAME, API_KEY)} | |
| def getAtricles(self): | |
| url = 'http://blog.hatena.ne.jp/{}/{}/atom/entry'.format(USER_NAME, BLOG_ID) | |
| r = requests.get(url, headers=self.headers) | |
| print r.text.encode('utf-8') |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
がおー(´・ω・`)
Invalid login