Created
January 27, 2014 17:59
-
-
Save gabegaster/8653941 to your computer and use it in GitHub Desktop.
Query Twine
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
''' | |
An example daemon to query twine and log results. | |
Gabe Gaster, Datascope Analytics, 2014 | |
[email protected] | |
''' | |
import requests, json, time | |
twine_id = "00000----------" # twine id | |
URL = "https://twine.cc/%s/rt?cached=1" % twine_id | |
# see: http://community.supermechanical.com/index.php?p=/discussion/7/api/p1 | |
# cookie copied from result of : | |
# wget -o log.txt --quiet -O temp.txt --keep-session-cookies --save-cookies cookies.txt --no-check-certificate --post-data="email=REPLACEWITHYOUREMAIL&password=REPLACEWITHYOURPASS" | |
# make your user_id a cookie | |
COOKIE = {'user_id':"NTAxMQ==|1390456333|8d6021e75575f15d8021363c5d850801435e95aa"} | |
def log(temp): | |
line = (map(str,(time.time(),temp))) | |
line = ",".join(line) + "\n" | |
with open("temp.log",'a') as f: | |
f.write(line) | |
print line[:-1] | |
def request(): | |
r = requests.get(URL,cookies=COOKIE) | |
data = json.loads(r.content) | |
age = data['age'] | |
temp= data['values'][1][1]/100 | |
return age, temp | |
def main(): | |
age = 10**10 | |
while 1: | |
new_age, temp = request() | |
if new_age < age: | |
log(temp) | |
age = new_age | |
time.sleep(60) | |
if __name__=="__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment