51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
|
# AGPL 3 or any later version
|
||
|
# (C) J.Y.Amihud ( Blender Dumbass )
|
||
|
|
||
|
import os
|
||
|
import json
|
||
|
import time
|
||
|
import email
|
||
|
import random
|
||
|
import hashlib
|
||
|
import urllib.parse
|
||
|
import urllib.request
|
||
|
|
||
|
from datetime import datetime
|
||
|
|
||
|
from modules import Set
|
||
|
from modules.Common import *
|
||
|
|
||
|
def Get(url, data=None, headers={}):
|
||
|
|
||
|
if data:
|
||
|
data = json.dumps(data).encode("utf-8")
|
||
|
req = urllib.request.Request(url, data=data, headers=headers)
|
||
|
f = urllib.request.urlopen(req, timeout=10)
|
||
|
data = json.loads(f.read().decode('utf-8'))
|
||
|
return data
|
||
|
|
||
|
def Value(url, keys):
|
||
|
|
||
|
data = Get(url)
|
||
|
for key in keys:
|
||
|
data = data[key]
|
||
|
return data
|
||
|
|
||
|
def Petition(article):
|
||
|
|
||
|
petition = article.get("petition", {})
|
||
|
api = petition.get("api", {})
|
||
|
timestamp = api.get("timestamp",0)
|
||
|
|
||
|
# 5 minutes delay
|
||
|
if time.time() - 300 < timestamp:
|
||
|
return
|
||
|
|
||
|
value = int(Value(api.get("api", ""), api.get("keys", [])))
|
||
|
article["petition"]["api"]["timestamp"] = time.time()
|
||
|
article["petition"]["signed"] = value
|
||
|
|
||
|
f = Set.Folder()
|
||
|
with open(f+"/tabs"+article.get("url", "")+"/metadata.json", "w") as save:
|
||
|
json.dump(article, save, indent=4)
|