This might be a stupid question, but here going nothing:
my counter starts at 2821614688517316738.
How can I add 1 to each for each iteration?
counter = 2821614688517316738
counter += 1
print(counter)
output:
2821614688517316739
2821614688517316739
2821614688517316739
How do I add 1 to it continuously, and not revert back to the original counter number?
Some of you asked for the full code, here it is.
Brief eacxplanation there are 3954 documents that it goes through. It connects to an API which required the counter to +1 for each iteration or request sent to API.
from bs4 import BeautifulSoup
import xml.etree.ElementTree as ET
import glob
import os
import hashlib
import hmac
import requests
import json
import pandas as pd
from pandas.io.json import json_normalize
path = "/Users/User/Downloads/Thesis papers/links/"
for filename in glob.glob(os.path.join(path, "*")):
with open(filename) as open_file:
content = open_file.read()
bs = BeautifulSoup(content, "xml")
for individual_xml in bs.find_all("Response"):
for link in individual_xml.find_all("Fields"):
for fields in link.find_all("Field"):
word = "Earnings Call"
if word in fields["value"]:
for i in link.find_all("Field", {"id":"7011"}):
#print(fields)
#print(i["value"][0])
#Your FactSet Information
key = ' *' #Insert Key from auth-factset.com
keyId = '*' #Insert KeyID from auth-factset.com
username = '*' #Insert your FactSet Username provided by your FactSet Account team
serial = '*' #Insert Serial Number tied to machine account provided by your FactSet Account
counter = 2821614688517316742
for gg in range(counter):
counter += 1
print(counter)
ba_key = bytearray.fromhex(key)
my_int = counter.to_bytes(8, 'big', signed=True)
my_hmac = hmac.new(ba_key,msg=my_int, digestmod=hashlib.sha512)
digested_counter = my_hmac.digest()
otp = digested_counter.hex()
json_object = {
'username': username,
'keyId': keyId,
'otp': otp ,
'serial': serial
}
OTP_url = 'https://auth.factset.com/fetchotpv1'
payload = json.dumps(json_object)
header = {'Content-Type': 'application/json'}
r = requests.post(OTP_url, data=payload)
r_key = r.headers.get(key='X-DataDirect-Request-Key')
r_token = r.headers.get(key='X-Fds-Auth-Token')
print('DataDirect Request Key: ', r_key)
print('Token:', r_token)
#Confirm authentication and session token work
header = {'X-Fds-Auth-Token':r_token}
Service_url = 'https://datadirect.factset.com/services/auth-test'
r = requests.get(Service_url,headers=header)
url = i["value"]
r = requests.get(url,headers=header)
#bs = BeautifulSoup(r, "xml")
#print(r.text)
with open(''+fields["value"]+''+'.xml', 'w') as f:
f.write(r.text)