Skip to content

Commit

Permalink
updated integration
Browse files Browse the repository at this point in the history
  • Loading branch information
danbryan committed Sep 2, 2023
1 parent 5e3f501 commit 728d945
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 27 deletions.
23 changes: 4 additions & 19 deletions integrations/google-calendar-urls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,19 @@ Integrate with the `cosmos-upgrades` API to fetch upgrade events and add them to
- Automatically creates Google Calendar events for each upgrade.
- Provides direct links to the relevant block details on Mintscan.

## Demo

## Prerequisites 📜

1. Python 3.6+
2. `requests` library (install via pip)

## Setup & Installation ⚙️

1. Clone the repository:
```bash
git clone <repository_url>
```

2. Install required packages:
```bash
pip install requests
```

3. Run the tool:
```bash
python <filename>.py
```

## Customizing Monitored Networks 🎛️

By default, the tool monitors a preset list of mainnets and testnets. If you're interested in specific networks, you can easily customize the list:

1. Open `app.py` in your preferred code editor.

2. Locate the `networks` dictionary:

```python
Expand Down Expand Up @@ -84,4 +69,4 @@ This project is open-source. Feel free to use, modify, and distribute as you see

---

Happy scheduling! 🌌🎉
Happy scheduling! 🌌🎉
31 changes: 24 additions & 7 deletions integrations/google-calendar-urls/app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import requests
import urllib.parse
from datetime import datetime, timedelta
from termcolor import colored
import pyshorteners
import pytz
from dateutil import tz
import json

def load_config():
with open('config.json', 'r') as f:
return json.load(f)


def get_events_from_api():
base_url = "https://cosmos-upgrades.apis.defiantlabs.net"
networks = {
"mainnets": "osmosis neutron nolus crescent akash cosmoshub sentinel stargaze omniflixhub cosmoshub terra kujira stride injective juno agoric evmos noble omny quasar dvpn onomy",
"testnets": "agorictestnet quasartestnet stridetestnet onomytestnet axelartestnet nibirutestnet nobletestnet dydxtestnet osmosistestnet cosmoshubtestnet"
}
config = load_config()
networks = config['networks']

events = []

Expand All @@ -25,16 +33,25 @@ def create_google_calendar_event(event_data):
event_title = f"{event_data['network']} - {event_data['type']} - {event_data['version']}"
details_url = f"https://www.mintscan.io/{event_data['network']}/blocks/{event_data['upgrade_block_height']}"

start_datetime = datetime.strptime(event_data['estimated_upgrade_time'], '%Y-%m-%dT%H:%M:%S.%f')

start_datetime = datetime.strptime(event_data['estimated_upgrade_time'], '%Y-%m-%dT%H:%M:%S.%f').replace(tzinfo=pytz.utc)
local_datetime = start_datetime.astimezone(tz.tzlocal()) # Using dateutil's tzlocal

end_datetime = start_datetime + timedelta(minutes=30)

start_time_str = start_datetime.strftime('%Y%m%dT%H%M%SZ')
end_time_str = end_datetime.strftime('%Y%m%dT%H%M%SZ')

google_cal_url = f"https://www.google.com/calendar/render?action=TEMPLATE&text={urllib.parse.quote(event_title)}&dates={start_time_str}/{end_time_str}&details={urllib.parse.quote(details_url)}&sf=true&output=xml"

s = pyshorteners.Shortener()
short_google_cal_url = s.tinyurl.short(google_cal_url)

print("\nEvent:", colored(event_title, 'cyan'))
print("Time (UTC):", colored(start_datetime.strftime('%Y-%m-%d %H:%M:%S'), 'yellow'), "(Local Time:", colored(local_datetime.strftime('%Y-%m-%d %H:%M:%S %Z'), 'magenta'), ")")
print("Details:", colored(details_url, 'green'))
print("Google Calendar Link:", colored(short_google_cal_url, 'blue'))
print("-" * 80) # This adds a separator line for better visibility.

print(google_cal_url)

def main():
events = get_events_from_api()
Expand Down
6 changes: 6 additions & 0 deletions integrations/google-calendar-urls/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"networks": {
"mainnets": "osmosis neutron nolus crescent akash cosmoshub sentinel stargaze omniflixhub cosmoshub terra kujira stride injective juno agoric evmos noble omny quasar dvpn onomy",
"testnets": "agorictestnet quasartestnet stridetestnet onomytestnet axelartestnet nibirutestnet nobletestnet dydxtestnet osmosistestnet cosmoshubtestnet"
}
}
6 changes: 5 additions & 1 deletion integrations/google-calendar-urls/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
requests
requests
termcolor
pyshorteners
pytz
python-dateutil

0 comments on commit 728d945

Please sign in to comment.