from __future__ import print_function import requests import gspread import string import math, datetime from oauth2client.service_account import ServiceAccountCredentials import readKeysLib # COUCOU # APIKeys and sheetKeys are saved in files in an external repertory see the module readKeysLib APIKey_dict,sheetKey_dict = readKeysLib.getDicts() repertory=sheetKey_dict['rep'] # Get authorization for gspread scope = ['https://spreadsheets.google.com/feeds'] json_keyfile=repertory+sheetKey_dict['jsonKey2'] credentials = ServiceAccountCredentials.from_json_keyfile_name(json_keyfile, scope) gc = gspread.authorize(credentials) sheetKey = sheetKey_dict['TornData'] def updatePersonalData(name, gc, sheetKey, APIKey_dict): APIKEY = APIKey_dict[name] r = requests.get( 'https://api.torn.com/user/?selections=basic,profile,jobpoints,bars,networth,crimes,education,profile,cooldowns,travel,personalstats,workstats,battlestats,inventory&key={api}'.format( api=APIKEY ) ).json() rbis = requests.get( 'https://api.torn.com/user/?selections=money,icons&key={api}'.format( api=APIKEY ) ).json() # incompatibility with networth torn = requests.get( 'https://api.torn.com/torn/?selections=education&key={api}'.format( api=APIKEY ) ).json() # incompatibility with networth # Open the google sheet (don't forget to share it with the gspread mail adress) ### [email protected] ### ws = gc.open_by_key(sheetKey).worksheet( 'RawData{}'.format(name) ) cell_list = ws.range( 'A2:B499' ) for i in range( len( cell_list ) ):
import requests, gspread, string, datetime from oauth2client.service_account import ServiceAccountCredentials import readKeysLib # COUCOU # APIKeys and sheetKeys are saved in files in an external repertory see the module readKeysLib APIKey_dict, sheetKey_dict, nodeName = readKeysLib.getDicts() repertory = sheetKey_dict['rep'] # Get authorization for gspread scope = ['https://spreadsheets.google.com/feeds'] json_keyfile=repertory+sheetKey_dict['jsonKey'] credentials = ServiceAccountCredentials.from_json_keyfile_name(json_keyfile, scope) gc = gspread.authorize(credentials) sheetKey = sheetKey_dict['TornStats'] def updateRehab(name, gc, sheetKey, APIKey_dict): APIKEY = APIKey_dict[name] # print ("updating {}'s Drugs History ({})".format( EXT, APIKEY )) # Get data from TORN in r (dictionnary) r=requests.get('https://api.torn.com/user/?selections=personalstats&key={api}'.format(api=APIKEY ) ).json() x=requests.get('https://api.torn.com/torn/?selections=items&key={api}'.format(api=APIKEY ) ).json() new_xantaken=r['personalstats']['xantaken'] new_lsdtaken=r['personalstats']['lsdtaken'] new_opitaken=r['personalstats']['opitaken'] new_pcptaken=r['personalstats']['pcptaken'] new_victaken=r['personalstats']['victaken'] xan_market_value=x['items']['206']['market_value'] lsd_market_value=x['items']['199']['market_value'] opi_market_value=x['items']['200']['market_value']