-
Notifications
You must be signed in to change notification settings - Fork 2
Sourcery Starbot ⭐ refactored closedLoop/fintech-sandbox-curation #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| ## Company Identifiers Conversion | ||
| ## -- Convert the jsonData to a Company Identifier | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return "%s?_token=%s&%s" % (self.base_url, self.access_token, formatted_parameters) | ||
|
|
||
| def query(self, country, date_range): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| return "%s?_token=%s&%s" % (self.base_url, self.access_token, formatted_parameters) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| elts = soup.findAll('article') | ||
| profiles = [] | ||
| for elt in elts: | ||
|
|
@@ -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, | ||
|
|
@@ -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'] | ||
|
|
@@ -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']) | ||
|
|
@@ -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()) | ||
|
|
@@ -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'" | ||
| #[](http://fintechsandbox.org/partner/thomson-reuters) | ||
|
|
||
|
Comment on lines
-225
to
+221
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| headings = ['Provider', | ||
| 'Resource Page', | ||
| 'External Profile', 'Website', 'Email', 'Phone','LinkedIn','Twitter'] | ||
|
|
@@ -235,19 +231,22 @@ def create_markup_table(df, profile_category): | |
| '[]({linkedin})', | ||
| '[]({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) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| def execute(info, sql, args=None, return_columns=False): | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| def executemany(info, sql, args=None): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
parse_linerefactored with the following changes:inline-immediately-returned-variable)