Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions data_providers/alexandria/integrations/ingest_alexandria.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,30 @@ def parse_line(line):

default = Sentiment

args = (Timestamp, default, StoryId, Country, Sentiment, \
Confidence, Novelty, Subjects, Relevance, Ticker, Timestamp, \
Ticker, Timestamp, default, StoryId, Timestamp, Country, \
Sentiment, Confidence, Novelty, Subjects, Relevance)

return args
return (
Timestamp,
default,
StoryId,
Country,
Sentiment,
Confidence,
Novelty,
Subjects,
Relevance,
Ticker,
Timestamp,
Ticker,
Timestamp,
default,
StoryId,
Timestamp,
Country,
Sentiment,
Confidence,
Novelty,
Subjects,
Relevance,
)
Comment on lines -62 to +85
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function parse_line refactored with the following changes:



def parse(fname):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@


def convertJsonTuple(jsonData):
data = json.loads(jsonData, object_hook=lambda d: namedtuple('data', d.keys())(*d.values()))
return data
return json.loads(
jsonData, object_hook=lambda d: namedtuple('data', d.keys())(*d.values()))
Comment on lines -15 to +16
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function convertJsonTuple refactored with the following changes:


## Company Identifiers Conversion
## -- Convert the jsonData to a Company Identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def construct_url(self, country, date_range):
"""
if date_range:
url_parameters = {"ReleasedOnStart": date_range[0], "ReleasedOnEnd": date_range[1], "CountryCode": country}
formatted_parameters = '&'.join('{0}={1}'.format(key, ''.join([str(var) for var in val])) for key, val in sorted(url_parameters.items()))
formatted_parameters = '&'.join(
'{0}={1}'.format(key, ''.join(str(var) for var in val))
for key, val in sorted(url_parameters.items())
)

Comment on lines -31 to +35
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function XigniteEconomicCalendar.construct_url refactored with the following changes:

return "%s?_token=%s&%s" % (self.base_url, self.access_token, formatted_parameters)

def query(self, country, date_range):
Expand Down
6 changes: 5 additions & 1 deletion data_providers/xignite/api/xignite/xignite_global_quotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ def construct_url(self, symbols):
"""
if symbols:
url_parameters = {"Identifiers": symbols,"IdentifierType": ["Symbol"]}
formatted_parameters = '&'.join('{0}={1}'.format(key, ','.join([str(var) for var in val])) for key, val in sorted(url_parameters.items()))
formatted_parameters = '&'.join(
'{0}={1}'.format(key, ','.join(str(var) for var in val))
for key, val in sorted(url_parameters.items())
)

Comment on lines -32 to +36
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function XigniteGlobalQuotes.construct_url refactored with the following changes:


return "%s?_token=%s&%s" % (self.base_url, self.access_token, formatted_parameters)

Expand Down
53 changes: 26 additions & 27 deletions fintech_sandbox/generate_data_partner_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def naming_convention(full_name):
def process_article(html):
import shutil
images_dir = WIKI_REPO_DIR + "images/"

soup = BeautifulSoup(html, 'lxml')

Comment on lines -28 to +30
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function process_article refactored with the following changes:

  • Extract guard clause from elif block (guard)
  • Replace if statement with if expression (assign-if-exp)

elts = soup.findAll('article')
profiles = []
for elt in elts:
Expand All @@ -36,13 +36,9 @@ def process_article(html):
text = elt.get_text().strip().splitlines()
if len(text):
text = text[0]

logo = img.attrs.get('src', None)
if logo:
img_name = urlparse.urlparse(logo).path.split('/')[-1]
else:
img_name = None

logo = img.attrs.get('src', None)
img_name = urlparse.urlparse(logo).path.split('/')[-1] if logo else None
profile = {
'logo': logo,
'img_name': img_name,
Expand All @@ -54,26 +50,28 @@ def process_article(html):
if profile['id'][-1] == '_':
profile['id'] = profile['id'][:-1]
profiles.append(profile)

for profile in profiles:
# Process bio
rs = requests.get('http://fintechsandbox.org' + profile['link'])
html = rs.content
soup = BeautifulSoup(html, 'lxml')

elts = soup.findAll('article')
title_elt = soup.find(name='h1', attrs={'class':'title'})
if title_elt:
profile.update({'title':title_elt.text.strip()})
desc_elt = soup.find(name='div', attrs={'class':'content'})
if desc_elt:
profile.update({'title':desc_elt.text.strip().splitlines()[0]})

# Process External Links
sidebar_elt = soup.find(name='div', attrs={'class':'sidebar'})
profile.update({'external_links': [{'url':elt.attrs['href'].strip(), 'text': elt.text.strip() } for elt in sidebar_elt.findAll('a')]})

for l in profile['external_links']:
if l['url'].find('fintechsandbox') > -1:
continue
if l['url'].find('mailto:') == 0:
profile['email_link'] = l['url']
profile['email_text'] = l['text']
Expand All @@ -84,12 +82,10 @@ def process_article(html):
profile['linkedin'] = l['url']
elif l['url'].find('twitter') > -1:
profile['twitter'] = l['url']
elif l['url'].find('fintechsandbox') > -1:
pass
else:
profile['website'] = l['url']


# Download logo
rs = requests.get(profile['logo'], stream=True)
logo_fname = '{}{}.{}'.format(images_dir, profile['id'], profile['logo_type'])
Expand All @@ -99,7 +95,7 @@ def process_article(html):
with open(logo_fname, 'wb') as f:
rs.raw.decode_content = True
shutil.copyfileobj(rs.raw, f)

import pandas as pd
df = pd.DataFrame(profiles)
df['name'] = df['name'].apply(lambda x: x.strip())
Expand Down Expand Up @@ -222,7 +218,7 @@ def create_markup_table(df, profile_category):

assert profile_category in ['Sandbox-Members','Data-Providers'], "profile_category must be either 'Sandbox-Members' or 'Data-Providers'"
#[![Fintech Sandbox Profile](images/thomson_reuters.png)](http://fintechsandbox.org/partner/thomson-reuters)

Comment on lines -225 to +221
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function create_markup_table refactored with the following changes:

headings = ['Provider',
'Resource Page',
'External Profile', 'Website', 'Email', 'Phone','LinkedIn','Twitter']
Expand All @@ -235,19 +231,22 @@ def create_markup_table(df, profile_category):
'[![{linkedin}](images/icons/linkedin.png)]({linkedin})',
'[![{twitter}](images/icons/twitter.png)]({twitter})'
]





table = ['| ' + ' | '.join(headings) +' |']
table.append('|' + '|'.join(['-'*len(h) for h in headings]) +'|')
for _, data in df.iterrows():
row = '| ' + ' | '.join([_process_template(t,data) for t in template]) +' |'




table = [
'| ' + ' | '.join(headings) + ' |',
'|' + '|'.join('-' * len(h) for h in headings) + '|',
]

for _, data in df.iterrows():
row = '| ' + ' | '.join(_process_template(t,data) for t in template) + ' |'
table.append(row)

markup = '\n'.join(table)

with open(WIKI_REPO_DIR + '{}.md'.format(profile_category), 'w') as fh:
fh.writelines(markup)

Expand Down
8 changes: 6 additions & 2 deletions member_sandbox/databases/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def nothing_to_return(sql):
"""
Evaluate if sql statement will return data or not
"""
return True if 'CREATE' in sql or 'UPDATE' in sql or 'INSERT' in sql or 'DELETE' in sql else False
return 'CREATE' in sql or 'UPDATE' in sql or 'INSERT' in sql or 'DELETE' in sql
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function nothing_to_return refactored with the following changes:



def execute(info, sql, args=None, return_columns=False):
Expand All @@ -46,7 +46,11 @@ def execute(info, sql, args=None, return_columns=False):
rows = c.fetchall()

# return the column names with the data
return tuple([desc[0] for desc in c.description]) + rows if return_columns else rows
return (
tuple(desc[0] for desc in c.description) + rows
if return_columns
else rows
)
Comment on lines -49 to +53
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function execute refactored with the following changes:



def executemany(info, sql, args=None):
Expand Down