-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature-#18' into develop
- Loading branch information
Showing
72 changed files
with
2,864 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
""" | ||
Descp: Script to fetch app's data and store it. | ||
Created on: 15-oct-2020 | ||
Copyright 2020-2021 Youssef 'FRYoussef' El Faqir El Rhazoui | ||
<[email protected]> | ||
""" | ||
|
||
import os | ||
import pandas as pd | ||
from typing import Dict, List | ||
from datetime import datetime, date | ||
|
||
from api_requester import ApiRequester | ||
|
||
|
||
APP_QUERY: str = '{{apps(first: {0}, skip: {1}\ | ||
){{id isForwarder isUpgradeable repoName repoAddress organization{{id}} }}}}' | ||
|
||
META_KEY: str = 'apps' | ||
|
||
|
||
def _request_apps(current_rows: int) -> List[Dict]: | ||
requester: ApiRequester = ApiRequester(endpoint=ApiRequester.ARAGON_MAINNET) | ||
print("Requesting App\'s data ...") | ||
start: datetime = datetime.now() | ||
|
||
apps: List[Dict] = requester.n_requests(query=APP_QUERY, skip_n=current_rows, | ||
result_key=META_KEY) | ||
|
||
print(f'App\'s data requested in {round((datetime.now() - start).total_seconds(), 2)}s') | ||
return apps | ||
|
||
|
||
def _transform_to_df(apps: List[Dict]) -> pd.DataFrame: | ||
for app in apps: | ||
org: str = app['organization']['id'] | ||
del app['organization'] | ||
app['organizationId'] = org | ||
|
||
return pd.DataFrame(apps) | ||
|
||
|
||
def update_apps(meta_data: Dict) -> None: | ||
apps: List[Dict] = _request_apps(current_rows=meta_data[META_KEY]['rows']) | ||
df: pd.DataFrame = _transform_to_df(apps=apps) | ||
|
||
filename: str = os.path.join('datawarehouse', 'aragon', f'{META_KEY}.csv') | ||
|
||
if os.path.isfile(filename): | ||
df.to_csv(filename, mode='a', header=False, index=False) | ||
else: | ||
df.to_csv(filename, index=False) | ||
|
||
print(f'Data stored in {filename}.\n') | ||
|
||
# update meta | ||
meta_data[META_KEY]['rows'] = meta_data[META_KEY]['rows'] + len(apps) | ||
meta_data[META_KEY]['lastUpdate'] = str(date.today()) | ||
|
||
|
||
if __name__ == '__main__': | ||
meta: dict = {META_KEY: {'rows': 0}} | ||
update_apps(meta_data=meta) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
""" | ||
Descp: Script to fetch Cast data and store it. Cast means vote. | ||
Created on: 16-oct-2020 | ||
Copyright 2020-2021 Youssef 'FRYoussef' El Faqir El Rhazoui | ||
<[email protected]> | ||
""" | ||
|
||
import os | ||
import pandas as pd | ||
from typing import Dict, List | ||
from datetime import datetime, date | ||
|
||
from api_requester import ApiRequester | ||
|
||
|
||
CAST_QUERY: str = '{{casts(first: {0}, skip: {1}\ | ||
){{id voteId voter supports voterStake createdAt vote{{orgAddress appAddress}} }}}}' | ||
|
||
META_KEY: str = 'casts' | ||
|
||
|
||
def _request_casts(current_rows: int) -> List[Dict]: | ||
requester: ApiRequester = ApiRequester(endpoint=ApiRequester.ARAGON_VOTING) | ||
print("Requesting Cast data ...") | ||
start: datetime = datetime.now() | ||
|
||
casts: List[Dict] = requester.n_requests(query=CAST_QUERY, skip_n=current_rows, | ||
result_key=META_KEY) | ||
|
||
print(f'Cast data requested in {round((datetime.now() - start).total_seconds(), 2)}s') | ||
return casts | ||
|
||
|
||
def _transform_to_df(casts: List[Dict]) -> pd.DataFrame: | ||
for cast in casts: | ||
org: str = cast['vote']['orgAddress'] | ||
app: str = cast['vote']['appAddress'] | ||
|
||
del cast['vote'] | ||
|
||
cast['orgAddress'] = org | ||
cast['appAddress'] = app | ||
|
||
return pd.DataFrame(casts) | ||
|
||
|
||
def update_casts(meta_data: Dict) -> None: | ||
casts: List[Dict] = _request_casts(current_rows=meta_data[META_KEY]['rows']) | ||
df: pd.DataFrame = _transform_to_df(casts=casts) | ||
|
||
filename: str = os.path.join('datawarehouse', 'aragon', f'{META_KEY}.csv') | ||
|
||
if os.path.isfile(filename): | ||
df.to_csv(filename, mode='a', header=False, index=False) | ||
else: | ||
df.to_csv(filename, index=False) | ||
|
||
print(f'Data stored in {filename}.\n') | ||
|
||
# update meta | ||
meta_data[META_KEY]['rows'] = meta_data[META_KEY]['rows'] + len(casts) | ||
meta_data[META_KEY]['lastUpdate'] = str(date.today()) | ||
|
||
|
||
if __name__ == '__main__': | ||
meta: dict = {META_KEY: {'rows': 0}} | ||
update_casts(meta_data=meta) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
""" | ||
Descp: Script to fetch MiniMeToken's data and store it. | ||
Created on: 15-oct-2020 | ||
Copyright 2020-2021 Youssef 'FRYoussef' El Faqir El Rhazoui | ||
<[email protected]> | ||
""" | ||
|
||
import os | ||
import pandas as pd | ||
from typing import Dict, List | ||
from datetime import datetime, date | ||
|
||
from api_requester import ApiRequester | ||
|
||
|
||
MINI_ME_TOKEN_QUERY: str = '{{miniMeTokens(first: {0}, skip: {1}\ | ||
){{id address totalSupply transferable name symbol orgAddress appAddress}}}}' | ||
|
||
META_KEY: str = 'miniMeTokens' | ||
|
||
|
||
def _request_mini_me_tokens(current_rows: int) -> List[Dict]: | ||
requester: ApiRequester = ApiRequester(endpoint=ApiRequester.ARAGON_TOKENS) | ||
print("Requesting Mini me token\'s data ...") | ||
start: datetime = datetime.now() | ||
|
||
tokens: List[Dict] = requester.n_requests(query=MINI_ME_TOKEN_QUERY, skip_n=current_rows, | ||
result_key=META_KEY) | ||
|
||
print(f'Mini me token\'s data requested in {round((datetime.now() - start).total_seconds(), 2)}s') | ||
return tokens | ||
|
||
|
||
def _transform_to_df(tokens: List[Dict]) -> pd.DataFrame: | ||
return pd.DataFrame(tokens) | ||
|
||
|
||
def update_tokens(meta_data: Dict) -> None: | ||
tokens: List[Dict] = _request_mini_me_tokens(current_rows=meta_data[META_KEY]['rows']) | ||
df: pd.DataFrame = _transform_to_df(tokens=tokens) | ||
|
||
filename: str = os.path.join('datawarehouse', 'aragon', f'{META_KEY}.csv') | ||
|
||
if os.path.isfile(filename): | ||
df.to_csv(filename, mode='a', header=False, index=False) | ||
else: | ||
df.to_csv(filename, index=False) | ||
|
||
print(f'Data stored in {filename}.\n') | ||
|
||
# update meta | ||
meta_data[META_KEY]['rows'] = meta_data[META_KEY]['rows'] + len(tokens) | ||
meta_data[META_KEY]['lastUpdate'] = str(date.today()) | ||
|
||
|
||
if __name__ == '__main__': | ||
meta: dict = {META_KEY: {'rows': 0}} | ||
update_tokens(meta_data=meta) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
""" | ||
Descp: Script to fetch organization's data and store it. | ||
Created on: 15-oct-2020 | ||
Copyright 2020-2021 Youssef 'FRYoussef' El Faqir El Rhazoui | ||
<[email protected]> | ||
""" | ||
|
||
import os | ||
import pandas as pd | ||
from typing import Dict, List | ||
from datetime import datetime, date | ||
|
||
from api_requester import ApiRequester | ||
|
||
|
||
ORGANIZATION_QUERY: str = '{{organizations(first: {0}, skip: {1}\ | ||
){{id createdAt recoveryVault}}}}' | ||
|
||
META_KEY: str = 'organizations' | ||
|
||
|
||
def _request_organizations(current_rows: int) -> List[Dict]: | ||
requester: ApiRequester = ApiRequester(endpoint=ApiRequester.ARAGON_MAINNET) | ||
print("Requesting Organization\'s data ...") | ||
start: datetime = datetime.now() | ||
|
||
orgs: List[Dict] = requester.n_requests(query=ORGANIZATION_QUERY, skip_n=current_rows, | ||
result_key=META_KEY) | ||
|
||
print(f'Organization\'s data requested in {round((datetime.now() - start).total_seconds(), 2)}s') | ||
return orgs | ||
|
||
|
||
def _transform_to_df(orgs: List[Dict]) -> pd.DataFrame: | ||
if not orgs: | ||
return pd.DataFrame() | ||
|
||
df: pd.DataFrame = pd.DataFrame(orgs) | ||
|
||
#TODO: temporal solution to non-attribute name | ||
df['name'] = df['id'].tolist() | ||
|
||
return df | ||
|
||
|
||
def update_organizations(meta_data: Dict) -> None: | ||
orgs: List[Dict] = _request_organizations(current_rows=meta_data[META_KEY]['rows']) | ||
df: pd.DataFrame = _transform_to_df(orgs=orgs) | ||
|
||
filename: str = os.path.join('datawarehouse', 'aragon', f'{META_KEY}.csv') | ||
|
||
if os.path.isfile(filename): | ||
df.to_csv(filename, mode='a', header=False, index=False) | ||
else: | ||
df.to_csv(filename, index=False) | ||
|
||
print(f'Data stored in {filename}.\n') | ||
|
||
# update meta | ||
meta_data[META_KEY]['rows'] = meta_data[META_KEY]['rows'] + len(orgs) | ||
meta_data[META_KEY]['lastUpdate'] = str(date.today()) | ||
|
||
|
||
if __name__ == '__main__': | ||
meta: dict = {META_KEY: {'rows': 0}} | ||
update_organizations(meta_data=meta) |
Oops, something went wrong.