|
| 1 | +""" |
| 2 | + Copyright (C) 2021 Gitcoin Core |
| 3 | +
|
| 4 | + This program is free software: you can redistribute it and/or modify |
| 5 | + it under the terms of the GNU Affero General Public License as published |
| 6 | + by the Free Software Foundation, either version 3 of the License, or |
| 7 | + (at your option) any later version. |
| 8 | +
|
| 9 | + This program is distributed in the hope that it will be useful, |
| 10 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + GNU Affero General Public License for more details. |
| 13 | +
|
| 14 | + You should have received a copy of the GNU Affero General Public License |
| 15 | + along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | +
|
| 17 | +""" |
| 18 | + |
| 19 | +import json |
| 20 | + |
| 21 | +from django.conf import settings |
| 22 | +from django.core.management.base import BaseCommand |
| 23 | + |
| 24 | +import requests |
| 25 | +from economy.models import EncodeAnything |
| 26 | +from perftools.models import JSONStore |
| 27 | + |
| 28 | + |
| 29 | +def polygon(): |
| 30 | + res = requests.get( |
| 31 | + f"https://api.polygonscan.com/api?module=gastracker&action=gasoracle&apikey={settings.POLYGONSCAN_API_KEY}" |
| 32 | + ) |
| 33 | + data = res.json()['result'] |
| 34 | + print(data) |
| 35 | + view = "gas_prices" |
| 36 | + keyword = "polygon" |
| 37 | + |
| 38 | + JSONStore.objects.filter(view=view, key=keyword).all().delete() |
| 39 | + data = json.loads(json.dumps(data, cls=EncodeAnything)) |
| 40 | + JSONStore.objects.create( |
| 41 | + view=view, |
| 42 | + key=keyword, |
| 43 | + data=data, |
| 44 | + ) |
| 45 | + |
| 46 | + |
| 47 | +class Command(BaseCommand): |
| 48 | + |
| 49 | + help = "get gas prices for networks" |
| 50 | + |
| 51 | + def handle(self, *args, **options): |
| 52 | + try: |
| 53 | + print("Polygon") |
| 54 | + polygon() |
| 55 | + except Exception as e: |
| 56 | + print(e) |
0 commit comments