123456789101112131415161718192021222324252627282930 |
- def archive_message(groupName, msgNumber, depth=0):
- global failed
- failed = False
- s = requests.Session()
- resp = s.get('https://groups.yahoo.com/api/v1/groups/' + groupName + '/messages/' + str(msgNumber) + '/raw', cookies={'T': cookie_T, 'Y': cookie_Y})
- if resp.status_code != 200:
- #some other problem, perhaps being refused access by Yahoo?
- #retry for a max of 3 times anyway
- if depth < 3:
- print ("Cannot get message " + str(msgNumber) + ", attempt " + str(depth+1) + " of 3 due to HTTP status code " + str(resp.status_code))
- time.sleep(0.1)
- archive_message(groupName,msgNumber,depth+1)
- else:
- if resp.status_code == 500:
- #we are most likely being blocked by Yahoo
- log("Archive halted - it appears Yahoo has blocked you.", groupName)
- log("Check if you can access the group's homepage from your browser. If you can't, you have been blocked.", groupName)
- log("Don't worry, in a few hours (normally less than 3) you'll be unblocked and you can run this script again - it'll continue where you left off." ,groupName)
- sys.exit()
- log("Failed to retrive message " + str(msgNumber) + " due to HTTP status code " + str(resp.status_code), groupName )
- failed = True
-
- if failed == True:
- return False
-
- msgJson = resp.text
- writeFile = open((groupName + "/" + str(msgNumber) + ".json"), "wb")
- writeFile.write(msgJson.encode('utf-8'))
- writeFile.close()
- return True
|