-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62799c8
commit 4ffd701
Showing
5 changed files
with
314 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,3 +77,6 @@ db.sqlite3 | |
.DS_Store | ||
.vscode | ||
.mypy_cache | ||
|
||
# Scripts results | ||
scripts/chainlist/result.txt |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
-r requirements.txt | ||
-r requirements-test.txt | ||
flake8 | ||
gitpython | ||
ipdb | ||
ipython | ||
isort | ||
|
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,45 @@ | ||
import json | ||
import shutil | ||
from glob import glob | ||
|
||
from git import Repo | ||
|
||
GIT_URL = "https://github.com/ethereum-lists/chains.git" | ||
REPO_DIR = "sources" | ||
RESULT_FILE_PATH = "result.txt" | ||
|
||
|
||
def clean_resources() -> None: | ||
"""Removes the intermediate resources used (source repository)""" | ||
try: | ||
shutil.rmtree(REPO_DIR) | ||
except OSError: | ||
pass | ||
|
||
|
||
def process_chains() -> None: | ||
""" | ||
Reads all JSON files in the REPO_DIR directory and processes the data | ||
in order to write one line per JSON to a result.txt file. Each line is | ||
formatted as 'CHAIN_NAME = CHAIN_ID' | ||
""" | ||
clean_resources() | ||
result_file = open(RESULT_FILE_PATH, "w") | ||
Repo.clone_from(GIT_URL, REPO_DIR) | ||
|
||
for f_name in glob(REPO_DIR + "/_data/chains/*.json"): | ||
f = open(f_name) | ||
data = json.load(f) | ||
|
||
result_file.write( | ||
"{} = {}\n".format( | ||
data["name"].upper().replace("-", "_").replace(" ", "_"), | ||
data["chainId"], | ||
) | ||
) | ||
|
||
clean_resources() | ||
|
||
|
||
if __name__ == "__main__": | ||
process_chains() |