Skip to content

Commit

Permalink
tests & path error fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarob96 committed Dec 13, 2018
1 parent 184d134 commit 4c39327
Show file tree
Hide file tree
Showing 19 changed files with 543 additions and 432 deletions.
2 changes: 1 addition & 1 deletion .idea/investing_scrapper.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

443 changes: 269 additions & 174 deletions .idea/workspace.xml

Large diffs are not rendered by default.

233 changes: 0 additions & 233 deletions data/tickers.csv

This file was deleted.

8 changes: 4 additions & 4 deletions investing_scrapper/data.py → investing_scrapper/Data.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class Data(object):
def __init__(self, date, close, open):
self.date = date
self.close = close
self.open = open
def __init__(self, date_, close_, open_):
self.date = date_
self.close = close_
self.open = open_

def to_dict(self):
return {
Expand Down
24 changes: 13 additions & 11 deletions investing_scrapper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import datetime
import os.path

import pandas as pd
import pkg_resources
import requests
from bs4 import BeautifulSoup

from investing_scrapper.Data import Data # TypeError: 'module' object is not callable
from investing_scrapper import user_agent as ua, tickers as ts
from investing_scrapper.data import Data


def get_recent_data(ticker):
if os.path.exists('tickers.csv') is False:
tickers = ts.get_ticker_names()
ts.convert_tickers_into_csv(tickers)

tickers = pd.read_csv('../data/tickers.csv')

for item in tickers:
if item['name'] == ticker:
resource_package = __name__
resource_path = '/'.join(('resources', 'tickers.csv'))
if pkg_resources.resource_exists(resource_package, resource_path):
tickers = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
else:
names = ts.get_ticker_names()
tickers = pd.DataFrame(names)

for row in tickers.itertuples():
if row.name.lower() == ticker.lower():
url = "https://es.investing.com/equities/" + ticker + "-historical-data"
headers = {
'User-Agent': ua.get_random()
Expand All @@ -41,7 +43,7 @@ def get_recent_data(ticker):

result = result[::-1]

df = pd.DataFrame.from_records([_.to_dict() for _ in result])
df = pd.DataFrame.from_records([value.to_dict() for value in result])
df.set_index('Date', inplace=True)

return df
Expand Down
Binary file modified investing_scrapper/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified investing_scrapper/__pycache__/data.cpython-36.pyc
Binary file not shown.
Binary file modified investing_scrapper/__pycache__/tickers.cpython-36.pyc
Binary file not shown.
Binary file modified investing_scrapper/__pycache__/user_agent.cpython-36.pyc
Binary file not shown.
Empty file.
Binary file not shown.
Loading

0 comments on commit 4c39327

Please sign in to comment.