Skip to content

Commit

Permalink
fix: add new addresses to existing project (#195)
Browse files Browse the repository at this point in the history
* fix: add new addresses to existing project

* fix: guild / agora.xyz

* fix: agora / guild collections

* fix: typo
  • Loading branch information
ccerv1 authored Jan 25, 2024
1 parent 2b2661f commit 9809f6c
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 19 deletions.
2 changes: 1 addition & 1 deletion data/collections/op-onchain.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ projects:
- acrypto-s
- adrastia-oracle
- aelin
- agoraxyz
- guildxyz
- aktionariat
- alchemix
- alliance-bridge
Expand Down
2 changes: 1 addition & 1 deletion data/collections/op-rpgf2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ projects:
- 0x-splits
- 0xparc
- across
- agoraxyz
- guildxyz
- akula-bft
- ante-finance
- ankr-network
Expand Down
2 changes: 1 addition & 1 deletion data/collections/op-rpgf3-endux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ projects:
- across
- acrypto-s
- aerodrome-finance
- agoraxyz
- guildxyz
- alchemyplatform
- alembic-tech
- alphadayhq
Expand Down
2 changes: 1 addition & 1 deletion data/collections/op-rpgf3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ projects:
- acrypto-s
- aerodrome-finance
- aestus-relay
- agoraxyz
- guildxyz
- alchemyplatform
- alembic-tech
- alloy-rs
Expand Down
2 changes: 1 addition & 1 deletion data/collections/optimism.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ projects:
- acrypto-s
- adrastia-oracle
- aelin
- agoraxyz
- guildxyz
- airgap-it
- aktionariat
- akula-bft
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
version: 3
slug: agoraxyz
name: Guild / Agora
slug: guildxyz
name: Guild.xyz
github:
- url: https://github.com/guildxyz
- url: https://github.com/agoraxyz
blockchain:
- address: "0x4F8f9f9469C4ecE49EaEfB9b0CDe35a652d9C1d6"
Expand Down
41 changes: 29 additions & 12 deletions src/scripts/update_project.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import json
import os
import sys
Expand All @@ -8,6 +9,7 @@

LOCAL_PATH = os.path.join(os.path.dirname(__file__), "..", "..", "data", "projects")

logging.basicConfig(level=logging.INFO, filename="update_project.log", filemode="w", datefmt="%Y-%m-%d %H:%M:%S", format="%(asctime)-15s %(levelname)-8s %(message)s")

def replace_single_quotes_with_double_quotes_in_file(file_path):
try:
Expand All @@ -19,9 +21,9 @@ def replace_single_quotes_with_double_quotes_in_file(file_path):
with open(file_path, 'w') as file:
file.write(modified_content)

print(f'Successfully replaced single quotes with double quotes in {file_path}')
logging.info(f'Successfully replaced single quotes with double quotes in {file_path}')
except Exception as e:
print(f'Error: {e}')
logging.error(f'Error replacing single quotes with double quotes in {file_path}: {e}')


def append_github_urls(filepath: str, github_url: str) -> None:
Expand All @@ -33,24 +35,24 @@ def append_github_urls(filepath: str, github_url: str) -> None:
github_url (str): The GitHub URL to add.
"""
if not os.path.exists(filepath):
print(f"File does not exist: {filepath}")
logging.error(f"File does not exist: {filepath}")
return

project_data = load_yaml_data(filepath)
if not project_data:
print(f"Error loading YAML data at {filepath}.")
logging.error(f"Error loading YAML data at {filepath}.")
return

yaml_url_data = project_data.get("urls", [])
url = github_url.lower().strip().strip("/")
if url in yaml_url_data:
print(f"URL {url} already exists.")
logging.warning(f"URL {url} already exists.")
return

yaml_url_data.append(url)
project_data["urls"] = yaml_url_data
dump(project_data, filepath)
print(f"Updated {filepath}")
logging.info(f"Updated {filepath}")
replace_single_quotes_with_double_quotes_in_file(filepath)


Expand All @@ -64,7 +66,7 @@ def update_addresses_from_json(filepath: str) -> None:
filepath (str): The file path of the JSON file containing address details.
"""
if not os.path.exists(filepath):
print("File does not exist.")
logging.error("File does not exist.")
return


Expand All @@ -75,31 +77,46 @@ def update_addresses_from_json(filepath: str) -> None:
for slug, addresses in data.items():
project_path = os.path.join(LOCAL_PATH, slug[0], f"{slug}.yaml")
if not os.path.exists(project_path):
print(f"File {project_path} does not exist.")
logging.warning(f"File {project_path} does not exist.")
continue

project_data = yaml_data.get(slug)
yaml_address_data = project_data.get("blockchain", {})
yaml_address_data = project_data.get("blockchain", [])
for address, details in addresses.items():
name = details.get("name")
networks = details.get("networks")
tags = details.get("tags")

for entry in yaml_address_data:
updated = False
for entry in yaml_address_data:
if entry['address'].lower() == address.lower():
if name and not entry.get("name"):
entry["name"] = name
entry["networks"] = list(set(entry.get("networks", []) + networks))
entry["tags"] = list(set(entry.get("tags", []) + tags))
logging.info(f"Updated {address} in {project_path}")
updated = True
break
if not updated:
entry = {
"address": address,
"networks": networks,
"tags": tags
}
if name:
entry["name"] = name
yaml_address_data.append(entry)
logging.info(f"Added {address} to {project_path}")

dump(project_data, project_path)
print(f"Updated {project_path}")
logging.info(f"Dumped YAML at {project_path}")
replace_single_quotes_with_double_quotes_in_file(project_path)


def main() -> None:
update_addresses_from_json(sys.argv[1])
inpath = sys.argv[1]
logging.info(f"Processing {inpath}")
update_addresses_from_json(inpath)


if __name__ == "__main__":
Expand Down

0 comments on commit 9809f6c

Please sign in to comment.