I am trying to execute this script:
import time
from SECEdgar.crawler import SecCrawler
def get_filings():
t1 = time.time()
# create object
seccrawler = SecCrawler()
companyCode = 'AAPL' # company code for apple
cik = '0000320193' # cik code for apple
date = '20010101' # date from which filings should be downloaded
count = '10' # no of filings
seccrawler.filing_10Q(str(companyCode), str(cik), str(date), str(count))
seccrawler.filing_10K(str(companyCode), str(cik), str(date), str(count))
seccrawler.filing_8K(str(companyCode), str(cik), str(date), str(count))
seccrawler.filing_13F(str(companyCode), str(cik), str(date), str(count))
t2 = time.time()
print "Total Time taken: ",
print (t2-t1)
if __name__ == '__main__':
get_filings()
I am putting this code in a file filings.py , then attempt to run it from terminal (Mac user)
python filings.py
But I am getting the following error:
Traceback (most recent call last):
File "filings.py", line 2, in <module>
from SECEdgar.crawler import SecCrawler
File "build/bdist.macosx-10.10-intel/egg/SECEdgar/crawler.py", line 6, in <module>
File "build/bdist.macosx-10.10-intel/egg/SECEdgar/config.py", line 22, in <module>
File "/Library/Python/2.7/site-packages/configparser.py", line 995, in __getitem__
raise KeyError(key)
KeyError: 'Paths'
What am I doing wrong?
Looks like there's an error in the package you installed.
Try uninstalling and reinstalling.
pip uninstall SECEdgar
pip install SECEdgar
I found the solution, it was basically a quite silly thing:
date = '20010101' # date from which filings should be downloaded
should be
date = '20010101' # date UNTIL which filings should be downloaded
so if you put the starting date you would end up with download 0 files, but if you put the end date then you would download them all successfully, seems to be working OK now :)
Related
So, i ran my "ml" model on my local windows machine, everything runs smooth, it just takes 48 hour to fully run every process, naturally i ask the company more procesing power to cut times, they give me a linux simulation server to run my models, but for some reason pandas is giving me the next error:
Traceback (most recent call last):
File "/ANACONDATA/Prediccion_de_Fallas/03_Modelos_y_Scripts/testv14.py", line 894, in <module>
dlist[xx][namer2] = np.where((dlist[xx].too_soon == 0),dlist[xx][column].shift(24) , 0)
File "/opt/anaconda3/lib/python3.9/site-packages/pandas/core/frame.py", line 3643, in __setitem__
self._setitem_array(key, value)
File "/opt/anaconda3/lib/python3.9/site-packages/pandas/core/frame.py", line 3702, in _setitem_array
self._iset_not_inplace(key, value)
File "/opt/anaconda3/lib/python3.9/site-packages/pandas/core/frame.py", line 3721, in _iset_not_inplace
raise ValueError("Columns must be same length as key")
this is the code where i fails (runs ok on windows), tried using pandas 1.3.5, and 1.4.2 same result
features=['AN_Utility_Supply_Press','AN_LPC_ASV_Position',
'AN_Eng_Brg_3Y_Gap',... 200 something list of features]
dlist = {}
turbo= np.unique(dfx2['SAP'])
for xx in (turbo):
dlist[xx]=dfx2.loc[(dfx2['SAP'] == xx)]
for column in dlist[xx][features]:
namer2=[column+'_'+'Lag']
fails here------>dlist[xx][namer2] = np.where((dlist[xx].too_soon == 0),dlist[xx][column].shift(24) , 0)
# namer3=[column+'_'+'Lchg'+"24"]
# dlist[xx][namer3] = np.where((dlist[xx].too_soon == 0),(dlist[xx][column]-dlist[xx][column].shift(24)) , 0)
namer4=[column+'_'+'mean']
dlist[xx][namer4] = np.where((dlist[xx].too_soon == 0),(dlist[xx][column].rolling(min_periods=1, window=feature_window).mean()), dlist[xx][column])
namer5=[column+'_'+'max']
dlist[xx][namer5] = np.where((dlist[xx].too_soon == 0),(dlist[xx][column].rolling(min_periods=1, window=feature_window).max()), dlist[xx][column])
dfx2 = pd.concat(dlist)
dfx2.reset_index(drop=True)
dfx2=dfx2.droplevel(level=0)
am i missing something?, why this happens?
Ok, took some time to figure it out, i tried more versions of pandas until it work, the version is 1.2.4 dont really have an explanation to what happen.
So im trying to make a raspberry pi project to take photos on schedule i have chrontab downpacked a little bit but i wanna name the files with the time/date they were taken at.
import datetime
dt = datetime.datetime.now().strftime("%m.%d.%Y - %H:%M")
print (dt)
Works like a charm but i cant save the "dt" variable as the name of the file.
import datetime
dt = datetime.datetime.now().strftime("%m.%d.%Y - %H:%M")
print (dt)
p = open('dt'.txt , 'w+')
11.03.2021 - 01:21
Traceback (most recent call last):
File "p.py", line 4, in <module>
p = open('dt'.txt , 'w+')
AttributeError: 'str' object has no attribute 'txt'
What am i doing wrong????????
I'm new to web scraping with python and am having a problem with the weather web scraping script I wrote. Here is the whole code 'weather.py':
#! python3
import bs4, requests
weatherSite = requests.get('https://weather.com/en-CA/weather/today/l/eef019cb4dca2160f08eb9714e30f28e05e624bbae351ccb6a855dbc7f14f017')
weatherSoup = bs4.BeautifulSoup(weatherSite.text, 'html.parser')
weatherLoc = weatherSoup.select('.CurrentConditions--location--kyTeL')
weatherTime = weatherSoup.select('.CurrentConditions--timestamp--23dfw')
weatherTemp = weatherSoup.select('.CurrentConditions--tempValue--3a50n')
weatherCondition = weatherSoup.select('.CurrentConditions--phraseValue--2Z18W')
weatherDet = weatherSoup.select('.CurrentConditions--precipValue--3nxCj > span:nth-child(1)')
location = weatherLoc[0].text
time = weatherTime[0].text
temp = weatherTemp[0].text
condition = weatherCondition[0].text
det = weatherDet[0].text
print(location)
print(time)
print(temp + 'C')
print(condition)
print(det)
It basically parses the weather information from 'The Weather Channel' and prints it out. This code was working fine yesterday when I wrote it. But, I tried today and it is giving me the following error:
Traceback (most recent call last):
File "C:\Users\username\filesAndStuff\weather.py", line 16, in <module>
location = weatherLoc[0].text
IndexError: list index out of range
Replace:
weatherLoc = weatherSoup.select('.CurrentConditions--location--kyTeL')
# print(weatherLoc)
# []
By:
weatherLoc = weatherSoup.select('h1[class*="CurrentConditions--location--"]')
# print(weatherLoc)
# [<h1 class="CurrentConditions--location--2_osB">Hamilton, Ontario Weather</h1>]
As you can see, your suffix kYTeL is not the same for me 2_osB. You need a partial match on class attribute (class*=) (note the *)
from dream.simulation.imports import Source, Queue, Machine, Exit
from dream.simulation.Globals import runSimulation
# define the objects of the model
S = Source('S1', 'Source', interArrivalTime={'Fixed': {'mean': 0.5}},
entity='Dream.Part')
Q = Queue('Q1', 'Queue', capacity=1)
M = Machine('M1', 'Machine', processingTime={'Fixed': {'mean': 0.25}})
E = Exit('E1', 'Exit')
# define predecessors and successors for the objects
S.defineRouting(successorList=[Q])
Q.defineRouting(predecessorList=[S], successorList=[M])
M.defineRouting(predecessorList=[Q], successorList=[E])
E.defineRouting(predecessorList=[M])
def main(test=0):
# add all the objects in a list
objectList = [S, Q, M, E]
# set the length of the experiment
maxSimTime = 1440.0
# call the runSimulation giving the objects and the length of the experiment
runSimulation(objectList, maxSimTime)
# calculate metrics
working_ratio = (M.totalWorkingTime / maxSimTime) * 100
# return results for the test
if test:
return {"parts": E.numOfExits, "working_ratio": working_ratio}
# print the results
print "the system produced", E.numOfExits, "parts"
print "the total working ratio of the Machine is", working_ratio, "%"
if __name__ == '__main__':
main()
Then I got messages as following:
Traceback (most recent call last):
File "Your directory/dream3/dream/stone/test1.py", line 6, in <module>
from dream.simulation.imports import Source, Queue, Machine, Exit
File "your directory\dream3\dream\simulation\imports.py", line 38, in <module>
from dream.simulation.Machine import Machine
File "your directory\dream3\dream\simulation\Machine.py", line 36, in <module>
from SkilledOperatorRouter import SkilledRouter
File "your directory\dream3\dream\simulation\SkilledOperatorRouter.py", line 32, in <module>
import Globals
File "your directory\dream3\dream\simulation\Globals.py", line 29, in <module>
from Machine import Machine
ImportError: cannot import name Machine
Good day, Sir!
For what it is worth, somebody had ported this library to Python 3
https://github.com/datarevenue-berlin/manpy
I installed this repo and the examples are working!
I am trying to read date from excel file using xlrd module. Below is my code for this :
# Variables
myfile = '/home/mobaxterm/.git/Operation_Documentation/docs/Servicing Portal User & Certificate Inventory.xlsx'
mydate = 'Expiration Date'
row_head = 0
# Import required modules
import xlrd
import datetime
today = datetime.date.today()
book = xlrd.open_workbook(myfile)
sheet = book.sheet_by_index(1)
for col_index in range(sheet.ncols):
print xlrd.cellname(row_head,col_index),"-",
print sheet.cell(row_head,col_index).value
if sheet.cell(row_head,col_index).value == mydate:
for raw_index in range(sheet.nrows):
expire = sheet.cell(raw_index,col_index).value
print expire
expire_date = datetime.datetime(*xlrd.xldate_as_tuple(expire, book.datemode))
print 'datetime: %s' % expire_date
break
While running the code i am getting following error :
Traceback (most recent call last):
File "cert_monitor.py", line 31, in <module>
expire_date = datetime.datetime(*xlrd.xldate_as_tuple(expire, book.datemode))
File "/usr/lib/python2.6/site-packages/xlrd/xldate.py", line 61, in xldate_as_tuple
xldays = int(xldate)
ValueError: invalid literal for int() with base 10: 'Expiration Date'
Can anyone suggest what could be the issue here?
Thanks for your time.
I believe that you should only skip the header:
for raw_index in range(1, sheet.nrows):
...
You are checking that sheet.cell(row_head,col_index).value == mydate, and then you want to iterate over the rows, but you should skip row_head first - it is ==mydate, which is not a date but a simple 'Expiration Date' string.