Improved project structure for the v2
This commit is contained in:
parent
88470055c8
commit
a87b891fa3
16 changed files with 65 additions and 162967 deletions
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
/facebook/token
|
||||
/washinsa/washinsa.json
|
||||
/facebook/facebook_data.json
|
||||
/dashboard/dashboard_data.json
|
||||
/menu/menu_data.json
|
|
@ -1,3 +1,3 @@
|
|||
# application-amicale-serveur
|
||||
# Serveur de l'application de l'Amicale
|
||||
|
||||
Partie serveur de l'application pour l'amicale
|
||||
Partie serveur de l'application pour l'amicale, publiée sous licence GPLv3.
|
|
@ -28,14 +28,19 @@
|
|||
# @midnight #Runs once a day [0 0 * * *]
|
||||
# @hourly #Runs once an hour [0 * * * *]
|
||||
|
||||
* * * * * cd $HOME/public_html/facebook/ && ./facebook_update.sh >/dev/null 2>&1
|
||||
# Call 2 times, one with a 30 sec delay
|
||||
* * * * * cd $HOME/public_html/ && ./update_washinsa.sh >/dev/null 2>&1
|
||||
* * * * * cd $HOME/public_html/ && (sleep 30 ; ./update_washinsa.sh) >/dev/null 2>&1
|
||||
# Update the menu every day
|
||||
0 0 * * * cd "$HOME"/public_html/v2/menu/ && ./menu_update.sh >/dev/null 2>&1
|
||||
|
||||
0 0 * * * cd $HOME/public_html/menu/ && ./menu_update.sh >/dev/null 2>&1
|
||||
# Update facebook data every minute
|
||||
* * * * * cd "$HOME"/public_html/v2/facebook/ && ./facebook_update.sh >/dev/null 2>&1
|
||||
|
||||
# Add at the end of the command to stop emails
|
||||
# Update the dashboard every 20 sec. The dashboard also update the machine list
|
||||
# Call 3 times, one with a 20 sec delay, and one with 40 sec, because cron cannot call more than each minute
|
||||
* * * * * cd "$HOME"/public_html/v2/dashboard && ./dashboard_update.sh >/dev/null 2>&1
|
||||
* * * * * cd "$HOME"/public_html/v2/dashboard && (sleep 20 ; ./dashboard_update.sh) >/dev/null 2>&1
|
||||
* * * * * cd "$HOME"/public_html/v2/dashboard && (sleep 40 ; ./dashboard_update.sh) >/dev/null 2>&1
|
||||
|
||||
# To stop emails, add the following at the end of each command:
|
||||
# >/dev/null 2>&1
|
||||
|
||||
|
||||
|
|
9
dashboard/dashboard_update.sh
Executable file
9
dashboard/dashboard_update.sh
Executable file
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Update washing machines
|
||||
cd "$HOME"/public_html/washinsa && ./washinsa_update.sh
|
||||
|
||||
# Update the dashboard with the new machine list
|
||||
touch lock
|
||||
python3 handler.py > log 2> err
|
||||
rm lock
|
|
@ -6,7 +6,12 @@ import os.path
|
|||
WASHINSA_FILE = '../washinsa/washinsa.json'
|
||||
MENU_FILE = '../menu/menu_data.json'
|
||||
FACEBOOK_FILE = '../facebook/facebook_data.json'
|
||||
|
||||
|
||||
WASHINSA_LOCK = '../washinsa/lock'
|
||||
MENU_LOCK = '../menu/lock'
|
||||
FACEBOOK_LOCK = '../facebook/lock'
|
||||
|
||||
PROXIMO_URL = 'https://etud.insa-toulouse.fr/~proximo/data/stock-v2.json'
|
||||
TUTORINSA_URL = 'https://etud.insa-toulouse.fr/~tutorinsa/api/get_data.php'
|
||||
PLANNING_URL = 'https://amicale-insat.fr/event/json/list'
|
||||
|
@ -20,6 +25,9 @@ def get_available_machines():
|
|||
|
||||
:return: a tuple containing the number of available dryers and washers
|
||||
"""
|
||||
# Prevent concurrent access to file
|
||||
while os.path.isfile(WASHINSA_LOCK):
|
||||
print("Waiting for washinsa lock")
|
||||
with open(WASHINSA_FILE) as f:
|
||||
data = json.load(f)
|
||||
available_dryers = 0
|
||||
|
@ -39,6 +47,9 @@ def get_today_menu():
|
|||
|
||||
:return: a list containing today's menu
|
||||
"""
|
||||
# Prevent concurrent access to file
|
||||
while os.path.isfile(MENU_LOCK):
|
||||
print("Waiting for menu lock")
|
||||
with open(MENU_FILE) as f:
|
||||
data = json.load(f)
|
||||
menu = []
|
||||
|
@ -84,13 +95,16 @@ def get_today_events():
|
|||
|
||||
:return: an array containing today's events
|
||||
"""
|
||||
with urllib.request.urlopen(PLANNING_URL) as response:
|
||||
data = json.loads(response.read().decode())
|
||||
today_events = []
|
||||
for event in data:
|
||||
if event['date_begin'].split(' ')[0] == date.today().strftime('%Y-%m-%d'):
|
||||
today_events.append(event)
|
||||
return today_events
|
||||
try:
|
||||
with urllib.request.urlopen(PLANNING_URL) as response:
|
||||
data = json.loads(response.read().decode())
|
||||
today_events = []
|
||||
for event in data:
|
||||
if event['date_begin'].split(' ')[0] == date.today().strftime('%Y-%m-%d'):
|
||||
today_events.append(event)
|
||||
return today_events
|
||||
except:
|
||||
return []
|
||||
|
||||
|
||||
def get_news_feed():
|
||||
|
@ -101,7 +115,7 @@ def get_news_feed():
|
|||
"""
|
||||
# Prevent concurrent access to file
|
||||
while os.path.isfile(FACEBOOK_LOCK):
|
||||
print("Waiting for lock")
|
||||
print("Waiting for Facebook lock")
|
||||
with open(FACEBOOK_FILE) as f:
|
||||
data = json.load(f)
|
||||
if 'data' in data and len(data['data']) > 15:
|
||||
|
@ -122,10 +136,8 @@ def generate_dashboard_json():
|
|||
return {
|
||||
'dashboard': {
|
||||
'today_events': get_today_events(),
|
||||
'available_machines': {
|
||||
'dryers': available_machines[0],
|
||||
'washers': available_machines[1]
|
||||
},
|
||||
'available_dryers': available_machines[0],
|
||||
'available_washers': available_machines[1],
|
||||
'available_tutorials': available_tutorials,
|
||||
'today_menu': get_today_menu(),
|
||||
'proximo_articles': get_proximo_article_number()
|
||||
|
|
162931
dashboard/log
162931
dashboard/log
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,10 @@
|
|||
#!/bin/bash
|
||||
|
||||
# A token is required to access the facebook public page
|
||||
# This token must be saved in a file named "token" in the same folder as this script
|
||||
# /!\ Do not sync this token with git /!\
|
||||
|
||||
touch lock
|
||||
#curl "https://graph.facebook.com/v3.3/amicale.deseleves/posts?fields=message%2Cfull_picture%2Ccreated_time%2Cpermalink_url&&date_format=U&access_token=EAAGliUs4Ei8BAGwHmg7SNnosoEDMuDhP3i5lYOGrIGzZBNeMeGzGhpUigJt167cKXEIM0GiurSgaC0PS4Xg2GBzOVNiZCfr8u48VVB15a9YbOsuhjBqhHAMb2sz6ibwOuDhHSvwRZCUpBZCjmAW12e7RjWJp0jvyNoYYvIQbfaLWi3Nk2mBc" > facebook_data.json
|
||||
curl "https://graph.facebook.com/v6.0/amicale.deseleves/published_posts?fields=full_picture,message,permalink_url,created_time&date_format=U&access_token=EAAGliUs4Ei8BAGwHmg7SNnosoEDMuDhP3i5lYOGrIGzZBNeMeGzGhpUigJt167cKXEIM0GiurSgaC0PS4Xg2GBzOVNiZCfr8u48VVB15a9YbOsuhjBqhHAMb2sz6ibwOuDhHSvwRZCUpBZCjmAW12e7RjWJp0jvyNoYYvIQbfaLWi3Nk2mBc" > facebook_data.json
|
||||
token=$(cat token)
|
||||
curl "https://graph.facebook.com/v7.0/amicale.deseleves/published_posts?fields=full_picture,message,permalink_url,created_time&date_format=U&access_token=$token" > facebook_data.json
|
||||
rm lock
|
||||
|
|
|
@ -33,4 +33,5 @@ def main():
|
|||
write_cleaned_data(get_cleaned_data())
|
||||
print('DONE')
|
||||
|
||||
|
||||
main()
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
touch lock
|
||||
curl "https://webservices-v2.crous-mobile.fr/ws/v1/regions/5/restaurants/114/menus" > menu_data.json && python3 handler.py
|
||||
curl "https://webservices-v2.crous-mobile.fr/ws/v1/regions/5/restaurants/114/menus" > menu_data.json && python3 handler.py > log 2> err
|
||||
rm lock
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd $HOME/public_html/washinsa
|
||||
# update washing machine list
|
||||
php index.php
|
||||
|
||||
cd ../expo_notifications
|
||||
# watch for new notifications with the new list
|
||||
python3 handler.py
|
||||
|
||||
cd ../dashboard
|
||||
# Update the dashboard
|
||||
python3 handler.py > log 2> err
|
5
washinsa/washinsa_update.sh
Executable file
5
washinsa/washinsa_update.sh
Executable file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
touch lock
|
||||
php index.php
|
||||
rm lock
|
Loading…
Reference in a new issue