Advertisement
Guest User

2ch.net API example client (Python)

a guest
Feb 20th, 2015
3,196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. import hmac
  2. import hashlib
  3. import urllib
  4. import urllib2
  5.  
  6. AppKey = 'xxfvFQcOzpTBvwuwPMwwzLZxiCSaGb'
  7. HMKey = 'DgQ3aNpoluV1cl3GFJAqitBg5xKiXZ'
  8.  
  9. def authenticate():
  10.     CT = '1234567890'
  11.     message = AppKey + CT
  12.     HB = hmac.new(HMKey, message, hashlib.sha256).hexdigest()
  13.     url = 'https://api.2ch.net/v1/auth/'
  14.     values = {'ID' : '', 'PW' : '', 'KY' : AppKey, 'CT' : CT, 'HB' : HB }
  15.     headers = { 'User-Agent' : '', 'X-2ch-UA': 'JaneStyle/3.80'}
  16.     data = urllib.urlencode(values)
  17.     req = urllib2.Request(url, data, headers)
  18.     response = urllib2.urlopen(req)
  19.     sid = response.read()
  20.     sid = sid.split(':')[1]
  21.     return sid
  22.  
  23. def getDAT(serverName, boardName, threadId, sid):
  24.     message = "/v1/" + serverName + "/" + boardName + "/" + threadId + sid + AppKey
  25.     hobo = hmac.new(HMKey, message, hashlib.sha256).hexdigest()
  26.     url = 'https://api.2ch.net/v1/' + serverName + "/" + boardName + "/" + threadId
  27.     values = { 'sid' : sid, 'hobo' : hobo, 'appkey': AppKey }
  28.     headers = { 'User-Agent' : 'Mozilla/3.0 (compatible; JaneStyle/3.80..)'}
  29.     data = urllib.urlencode(values)
  30.     req = urllib2.Request(url, data, headers)
  31.     response = urllib2.urlopen(req)
  32.     return response.read()
  33.    
  34. sid = authenticate()
  35. dat = getDAT('anago', 'software', '1424327586', sid)
  36. print dat
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement