-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonFile.py
More file actions
57 lines (41 loc) · 1.68 KB
/
monFile.py
File metadata and controls
57 lines (41 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python
#Sample python script that will read your remote favorites file.
#It will see if the favorites file has changed (via a checksum) and if so it will send a
#post request to the MMM-PGA module to update the favorites. It give the ability to dynamically
#update your favorite list without having to restart the mirror. I placed the job in cron so
#that i can change my favorites on drop box share and not have to either restart the mirror or
#send an post via curl
import os
import hashlib
import time
import requests
import time
remotefile = "YOUR FILE HERE OR URL"
#File to store the previous checksum get update everytime a change is detected
oldchksumfile = "YOURPATH/oldchecksum.txt"
url = "http://YOURHOST:8080/MMM-PGA-UpdateFavs"
## IF Using Local File Replace the two lines below with
# with open (remotefile,'r') as file:
# data =file.read()
# curchksum = hashlib.md5(data).hexdigest()
#Generate chksum of the current fav file
curfile = requests.get(remotefile)
curchksum = hashlib.md5(curfile.content).hexdigest()
#Gets the previous checksum from the file
with open(oldchksumfile,'r') as file:
oldchksum = file.read().replace('\n','')
#if chksum do not match
# Update the checksum file
# Send post to update mirror
t = time.localtime()
current_time = time.strftime("%H:%M:%S", t)
if oldchksum != curchksum:
print (current_time + " Update the Mirror")
with open(oldchksumfile,"w") as file:
file.write(curchksum)
res = requests.post(url,"")
t = time.localtime()
current_time = time.strftime("%H:%M:%S", t)
print (current_time + " Request Sent to Update Favorites res:" + res.text)
else:
print (current_time + " No update needed")