use poetry and check favorites instead of watchlist
This commit is contained in:
		
							
								
								
									
										0
									
								
								tgtg_notifier/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tgtg_notifier/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										6
									
								
								tgtg_notifier/config.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								tgtg_notifier/config.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| import json | ||||
|  | ||||
| CREDFILE = ".credentials.json" | ||||
|  | ||||
| with open('.config.json', 'r') as f: | ||||
|     config = json.load(f) | ||||
							
								
								
									
										12
									
								
								tgtg_notifier/login.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								tgtg_notifier/login.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| import json | ||||
| from tgtg import TgtgClient | ||||
|  | ||||
| from .config import config, CREDFILE | ||||
|  | ||||
| def main(): | ||||
|     client = TgtgClient(email=config['email']) | ||||
|     credentials = client.get_credentials() | ||||
|  | ||||
|     with open(CREDFILE, 'w') as f: | ||||
|         print(credentials) | ||||
|         json.dump(credentials, f) | ||||
							
								
								
									
										63
									
								
								tgtg_notifier/notifier.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								tgtg_notifier/notifier.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,63 @@ | ||||
| from tgtg import TgtgClient | ||||
| from pprint import pprint | ||||
| import json | ||||
| import time | ||||
| import requests | ||||
| import random | ||||
| import schedule | ||||
| from collections import defaultdict | ||||
| from .config import CREDFILE, config  | ||||
|  | ||||
| previous = defaultdict(int) | ||||
|  | ||||
| creds = {} | ||||
|  | ||||
| with open('.credentials.json', 'r') as f: | ||||
|     creds = json.load(f) | ||||
|  | ||||
| NTFY_CHANNEL = config["ntfy_channel"] | ||||
|  | ||||
| NTFY_CHANNEL_DEBUG = NTFY_CHANNEL + "-debug" | ||||
|  | ||||
|  | ||||
| client = TgtgClient(access_token=creds["access_token"], refresh_token=creds["refresh_token"], user_id=creds["user_id"], cookie=creds["cookie"]) | ||||
|  | ||||
|  | ||||
| def check(item): | ||||
|     #pprint(item) | ||||
|     available = int(item["items_available"]) | ||||
|     id = item["store"]["store_id"] | ||||
|     print(f"{id:<10} - { item['display_name']}: { item['items_available']} available") | ||||
|     if available != previous[id]: | ||||
|         previous[id] = available | ||||
|         notify(f"{ available } disponibles para {item['display_name'] }") | ||||
|     return available | ||||
|  | ||||
|  | ||||
| def notify(data, url=NTFY_CHANNEL): | ||||
|     print(f"Sending {data} to {url}") | ||||
|     requests.post(url, | ||||
|                   data=data.encode(encoding='utf-8')) | ||||
|  | ||||
|  | ||||
| def check_watchlist(): | ||||
|     watchlist = client.get_items(favorites_only=True) | ||||
|     total = 0 | ||||
|     for item in watchlist: | ||||
|         #item = client.get_item(id) | ||||
|         total += check(item) | ||||
|         time.sleep(random.randint(2, 10)) | ||||
|  | ||||
| def notify_all(): | ||||
|     total = sum(previous.values()) | ||||
|     notify(f"List checked. Total available: {total}", url=NTFY_CHANNEL_DEBUG) | ||||
|  | ||||
|  | ||||
| schedule.every(1).minutes.do(check_watchlist) | ||||
| schedule.every(60).minutes.do(notify_all) | ||||
|  | ||||
|  | ||||
| while True: | ||||
|     schedule.run_pending() | ||||
|     #check_watchlist() | ||||
|     time.sleep(30) | ||||
		Reference in New Issue
	
	Block a user