这可能是一个愚蠢的问题,但是什么也没做:
我的计数器从2821614688517316738开始。
如何为每个迭代加1?
counter = 2821614688517316738
counter += 1
print(counter)
输出:
2821614688517316739
2821614688517316739
2821614688517316739
如何连续向其添加1,而不恢复为原始计数器编号?
你们中的一些人要求完整的代码,就在这里。
简要介绍共有3954个文档。它连接到API,对于每次发送到API的迭代或请求,计数器都需要+1。
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)
问题来源:stackoverflow
它将遍历计数器并继续在其中添加数字
counter = 2821614688517316738
for i in range(3954):
counter += 1
print(counter)
回答来源:stackoverflow
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。