Skip to content

Commit 18bbe31

Browse files
authored
Merge pull request #3 from TobiasS1402/dev-env
Dev env
2 parents e4c974e + 4ffe15b commit 18bbe31

3 files changed

Lines changed: 45 additions & 12 deletions

File tree

.github/workflows/docker-publish.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ name: Docker
66
# documentation.
77

88
on:
9-
push:
10-
branches: [ "master" ]
11-
# Publish semver tags as releases.
12-
tags: [ 'v*.*.*' ]
139
pull_request:
1410
branches: [ "master" ]
11+
tags: [ 'v*.*.*' ]
1512

1613
env:
1714
# Use docker.io for Docker Hub if empty

main.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import requests
33
import json
44
import logging
5-
from dotenv import dotenv_values
5+
import os
6+
from dotenv import load_dotenv
67
from apscheduler.schedulers.blocking import BlockingScheduler
78

89

@@ -16,8 +17,11 @@ def readConfig():
1617
'''
1718
reading environment variables
1819
'''
19-
logging.info("Environment file has been read")
20-
return dotenv_values(".env")
20+
if os.path.exists('.env') == True:
21+
load_dotenv()
22+
return logging.info("Environment file has been read")
23+
else:
24+
return logging.info(".env file not present, falling back to normal Environment")
2125

2226
def init(latitude, longitude):
2327
'''
@@ -27,7 +31,7 @@ def init(latitude, longitude):
2731
url = "https://www.ah.nl/gql" #open gql endpoint for anonymous requests
2832
headers = {'Client-Name': 'ah-stores','Client-Version':'0.230.0'} #Missing client identification. Requests should include \"client-name\" and \"client-version\" headers
2933
gql_body = """query stores($filter: StoreFilterInput, $size: PageSize!, $start: Int) {stores(filter: $filter, size: $size, start: $start) { result { ...storeList __typename} page { total hasNextPage __typename} __typename }}fragment storeList on Store { id name storeType phone distance address { ...storeAddress __typename } geoLocation { latitude longitude __typename} openingDays { ...openingDaysInfo __typename } __typename}fragment storeAddress on StoreAddress { city street houseNumber houseNumberExtra postalCode countryCode __typename}fragment openingDaysInfo on StoreOpeningDay { dayName type date openingHour { ...storeOpeningHour __typename } }fragment storeOpeningHour on StoreOpeningHour { date openFrom openUntil __typename}"""
30-
json_data = {"operationName":"stores","variables":{"filter":{"location":{"latitude":latitude,"longitude":longitude}},"start":0,"size":readConfig().get('number_of_stores')},"query": gql_body} #tweak size: number of albert heijns this variable is for filtering
34+
json_data = {"operationName":"stores","variables":{"filter":{"location":{"latitude":latitude,"longitude":longitude}},"start":0,"size":os.environ['number_of_stores']},"query": gql_body} #tweak size: number of albert heijns this variable is for filtering
3135
response = requests.post(url=url, headers=headers, json=json_data, ) #simple post request putting it all together
3236

3337
if response.status_code == 200:
@@ -106,8 +110,8 @@ def telegramConnection(appieNotification):
106110
'''
107111
setting up api connection for sending Telegram messages
108112
'''
109-
bot_token = readConfig().get('telegram_bot_token')
110-
bot_chatID = readConfig().get('telegram_chat_id')
113+
bot_token = os.environ['telegram_bot_token']
114+
bot_chatID = os.environ['telegram_chat_id']
111115
send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=Markdown&text=' + appieNotification
112116
response = requests.get(send_text)
113117
logging.info(response.json)
@@ -117,7 +121,7 @@ def boxRequests():
117121
'''
118122
function where the magic happens: it connects to the local sqlite db, connects authenticated to the surprise-boxes api and executes queries on the database
119123
'''
120-
results = init(float(readConfig().get('latitude')),float(readConfig().get('longitude'))) #Don't forget to make this a variable / cli parameter
124+
results = init(float(os.environ['latitude']),float(os.environ['longitude'])) #Don't forget to make this a variable / cli parameter
121125
sqliteConnection = sqlite3.connect('appie.db')
122126
cursor = sqliteConnection.cursor()
123127
for key,value in results.items():

readme.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,39 @@ A simple Python program for polling the Albert Heijn REST and Graph API's to get
3939

4040
The program works by grabbing the nearest x (default 5) number of Albert Heijn stores based on your latitude and longitude. After this it keeps a record of stores with boxes available and it will send you a Telegram notification when something's changed. e.g. boxes are available, a box is gone, everything is gone.
4141

42-
## :checkered_flag: Starting ##
42+
## ☸ Running inside a container ##
43+
44+
### 🚢 pulling from ghcr.io ###
45+
```bash
46+
# Clone this project
47+
$ docker pull ghcr.io/tobiass1402/appiesniper:v0.1.2
48+
49+
# Run the project with env file
50+
$ docker run --env-file ./.env -d ghcr.io/tobiass1402/appiesniper:v0.1.2r
51+
52+
# Run the project with docker env variables
53+
$ docker run -d ghcr.io/tobiass1402/appiesniper:v0.1.2 -e longitude=5.1331746 -e latitude=51.5868726 -e telegram_bot_token='xxxxxxxx:xxxxxxxxxxxxxxxxxxxx' -e telegram_chat_id='xxxxxxxx' -e number_of_stores=5
54+
```
55+
56+
### 🔨 Building it yourself ###
57+
```bash
58+
# Clone this project
59+
$ git clone https://github.com/TobiasS1402/appiesniper
60+
61+
# Access
62+
$ cd appiesniper
63+
64+
# Build the container environment
65+
$ docker build . -t tobiass1402/appiesniper
66+
67+
# Run the project with env file
68+
$ docker run --env-file ./.env -d tobiass1402/appiesniper
69+
70+
# Run the project with docker env variables
71+
$ docker run -d tobiass1402/appiesniper -e longitude=5.1331746 -e latitude=51.5868726 -e telegram_bot_token='xxxxxxxx:xxxxxxxxxxxxxxxxxxxx' -e telegram_chat_id='xxxxxxxx' -e number_of_stores=5
72+
```
73+
74+
## ☸ Running standalone ##
4375

4476
```bash
4577
# Clone this project

0 commit comments

Comments
 (0)