Skip to content

Commit fadd0ee

Browse files
authored
Merge pull request #2 from etheralpha/update-diff
track newly added entries
2 parents b90e048 + 7168c91 commit fadd0ee

File tree

6 files changed

+162
-0
lines changed

6 files changed

+162
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Update Data Hourly
2+
3+
on:
4+
schedule:
5+
- cron: '0 * * * *'
6+
workflow_dispatch:
7+
8+
jobs:
9+
update_data:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Check out repository
14+
uses: actions/checkout@v2
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v2
18+
with:
19+
python-version: 3.x
20+
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install -r _scripts/requirements.txt
25+
26+
- name: Fetch latest changes
27+
run: |
28+
git fetch origin main
29+
git reset --hard origin/main
30+
31+
- name: Run Python script
32+
run: python _scripts/update_data.py
33+
env:
34+
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
35+
36+
- name: Commit and push changes
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
run: |
40+
git config --global user.name "github-actions[bot]"
41+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
42+
git add *
43+
git diff --quiet && git diff --staged --quiet || (git commit -m "[BOT] Update data" && git push https://${GITHUB_TOKEN}@github.com/${{ github.repository }}.git HEAD:${{ github.ref }})

_data/adoption-new-entries.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"date": "2025-01-16", "status": "live", "entities": ["PostFinance AG"], "products": ["ETH Staking"], "chains": ["Mainnet"], "sources": ["https://archive.md/UMwxE#selection-2107.0-2107.5"], "is_recent": true}, {"date": "2025-01-08", "status": "dev", "entities": ["Gelephu Mindfulness City, Bhutan"], "products": ["ETH Strategic Reserve"], "chains": [null], "sources": ["https://gmc.bt/digitalassets/"], "is_recent": true}]

_data/adoption-old.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

_scripts/requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
python-dotenv==1.0.1
2+
PyYAML==6.0.1
3+
Requests==2.32.2
4+
python-dateutil==2.8.2

_scripts/update_data.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# compares the current day's adoption list to the previous days to check if anything new has been added
2+
# new additions are added to adoption-newly-added.json
3+
# new additions have the `is_recent` property with `True` or `False` values
4+
# `True` means it was added as a new news (more recent than the most recent additon from the previous day)
5+
# `False` means it was an old event that was missing from the list
6+
7+
import os
8+
import time
9+
from datetime import datetime, timezone
10+
import json
11+
import yaml
12+
import requests
13+
from urllib.parse import quote
14+
from dotenv import load_dotenv
15+
16+
17+
load_dotenv()
18+
TELEGRAM_BOT_TOKEN = os.environ.get("TELEGRAM_BOT_TOKEN")
19+
20+
21+
current_time = round(time.time()) # seconds
22+
date = datetime.now(timezone.utc).strftime('%Y-%m-%d') # yyyy-mm-dd
23+
print(f"Epoch: {current_time}")
24+
print(f"Date: {date}")
25+
26+
27+
# load/sort old adoption list
28+
repo_root = os.path.abspath(__file__ + '/../../')
29+
old_adoption_list_path = repo_root + '/_data/adoption-old.json'
30+
with open(old_adoption_list_path, 'r') as old_adoption_list_file:
31+
old_adoption_list = json.load(old_adoption_list_file)
32+
old_adoption_list = sorted(old_adoption_list, key=lambda x: x['date'], reverse=True)
33+
print(f"old_adoption_list count: {len(old_adoption_list)}")
34+
35+
36+
# load/sort current adoption list
37+
request = requests.get('https://ethereumadoption.com/adoption.json')
38+
current_adoption_list = request.json()
39+
current_adoption_list = sorted(current_adoption_list, key=lambda x: x['date'], reverse=True)
40+
print(f"current_adoption_list count: {len(current_adoption_list)}")
41+
42+
43+
44+
# create list of new entries
45+
new_entries = []
46+
is_recent = True
47+
for current_entry in current_adoption_list:
48+
has_match = False
49+
for old_entry in old_adoption_list:
50+
if current_entry == old_entry:
51+
has_match = True
52+
is_recent = False
53+
if has_match == False:
54+
new_entry = dict(current_entry)
55+
new_entry['is_recent'] = is_recent
56+
new_entries.append(new_entry)
57+
print(f"new_entries count: {len(new_entries)}")
58+
59+
60+
# save new entries to file
61+
new_entries_path = repo_root + '/_data/adoption-new-entries.json'
62+
with open(new_entries_path, "w") as new_entries_file:
63+
json.dump(new_entries, new_entries_file)
64+
65+
66+
# save current list as old list for next update
67+
with open(old_adoption_list_path, "w") as old_adoption_list_file:
68+
json.dump(current_adoption_list, old_adoption_list_file)
69+
70+
71+
# post new entries to telegram
72+
new_entries.reverse()
73+
print(new_entries)
74+
75+
76+
for entry in new_entries:
77+
if entry['is_recent']:
78+
status = ''
79+
# if entry['status'] == 'dev':
80+
# status = '[dev] '
81+
entities = '/'.join(entry['entities'])
82+
products = ', '.join(entry['products'])
83+
source = entry['sources'][0]
84+
support = ''
85+
if entry['chains'][0] != None:
86+
chains = ', '.join(entry['chains'])
87+
support = f" with support for {chains}"
88+
# use endpoint to get channel id after interacting with bot (/start)
89+
# https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/getUpdates
90+
chat_list = [
91+
"-1002400345737" # @ethereumadoption
92+
]
93+
message = f"{status}{entities} announces {products}{support}"
94+
message = f"{message.upper()}\n\n{source}"
95+
for chat_id in chat_list:
96+
url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
97+
params = {
98+
'chat_id': chat_id,
99+
'text': message,
100+
'reply_markup': json.dumps({
101+
'inline_keyboard': [[{
102+
'text': 'EthereumAdoption.com',
103+
'url': 'https://ethereumadoption.com'
104+
}]]
105+
})
106+
}
107+
print(requests.get(url=url, params=params).json())
108+
time.sleep(1)
109+
110+

adoption-new-entries.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
---
3+
{{ site.data.adoption-new-entries | jsonify }}

0 commit comments

Comments
 (0)