· 6 years ago · Mar 12, 2020, 12:40 PM
1from bs4 import BeautifulSoup
2import xml.etree.ElementTree as ET
3import glob
4import os
5import hashlib
6import hmac
7import requests
8import json
9import pandas as pd
10from pandas.io.json import json_normalize
11print("top")
12path = "/Users/Muhammed/Downloads/Thesis papers/links/"
13counter = 2821614688517316784
14for gg in range(3954):
15 counter += 1
16 print(counter)
17 for filename in glob.glob(os.path.join(path, "*")):
18 with open(filename) as open_file:
19 content = open_file.read()
20 bs = BeautifulSoup(content, "xml")
21 print("loading BS")
22 for individual_xml in bs.find_all("Response"):
23 for link in individual_xml.find_all("Fields"):
24 for fields in link.find_all("Field"):
25 word = "Earnings Call"
26 if word in fields["value"]:
27
28 for i in link.find_all("Field", {"id":"7011"}):
29 #print(fields)
30 #print(i["value"][0])
31 print("Connecting to API")
32
33 #Your FactSet Information
34 key = ' ffd2d57749bfaa7392df40d2a238ffc63faf08a4528e82c667d4e343c0a6e5469ebaf49a59443aef302f071ab6cf047f136d357d58fdd85ed00eb8ea3d27c459' #Insert Key from auth-factset.com
35 keyId = 'AAAA' #Insert KeyID from auth-factset.com
36 username = 'CARNEGIE_EC' #Insert your FactSet Username provided by your FactSet Account team
37 serial = '1042440' #Insert Serial Number tied to machine account provided by your FactSet Account
38 #counter = 2821614688517316782 #282161468851731620
39 ba_key = bytearray.fromhex(key)
40 my_int = counter.to_bytes(8, 'big', signed=True)
41 my_hmac = hmac.new(ba_key,msg=my_int, digestmod=hashlib.sha512)
42 digested_counter = my_hmac.digest()
43 otp = digested_counter.hex()
44 json_object = {
45 'username': username,
46 'keyId': keyId,
47 'otp': otp ,
48 'serial': serial
49 }
50 OTP_url = 'https://auth.factset.com/fetchotpv1'
51 payload = json.dumps(json_object)
52 header = {'Content-Type': 'application/json'}
53 r = requests.post(OTP_url, data=payload)
54 r_key = r.headers.get(key='X-DataDirect-Request-Key')
55 r_token = r.headers.get(key='X-Fds-Auth-Token')
56 print('DataDirect Request Key: ', r_key)
57 print('Token:', r_token)
58 #Confirm authentication and session token work
59 header = {'X-Fds-Auth-Token':r_token}
60 Service_url = 'https://datadirect.factset.com/services/auth-test'
61 r = requests.get(Service_url,headers=header)
62 url = i["value"]
63 r = requests.get(url,headers=header)
64 print(r.text)
65 with open(''+fields["value"]+''+'.xml', 'w') as f:
66 f.write(r.text)