-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
105 lines (99 loc) · 3.84 KB
/
app.py
File metadata and controls
105 lines (99 loc) · 3.84 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from datetime import date, datetime, time
from flask import Flask
from flask import abort
import requests
from requests.api import get
from flask import request
from flask_cors import CORS
import json
import lxml.html as lh
import string
import os
from dotenv import load_dotenv
load_dotenv()
from requests.models import Response
import logging
app = Flask(__name__)
cors = CORS(app, resources={r"/*": {"origins": "*"}})
try:
import http.client as http_client
except ImportError:
# Python 2
import httplib as http_client
http_client.HTTPConnection.debuglevel = 1
# You must initialize logging, otherwise you'll not see debug output.
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
@app.route("/returnid")
def returnid():
file = open("alumnos.json", 'r', encoding="utf8")
jsonAlu = json.loads(file.read())
name = str(request.args.get('name'))
secName = str(request.args.get('secname'))
surname = str(request.args.get('surname'))
if len(secName) <= 0:
contructedName = str(surname + ' ' + name)
contructedName = contructedName.upper()
id = jsonAlu.get(contructedName)
else:
contructedName = str(surname + ' ' + name + ' ' + secName)
contructedName = contructedName.upper()
id = jsonAlu.get(contructedName)
if id:
return str(id)
else:
abort(404)
@app.route("/returnname")
def returnname():
file = open("ids.json", 'r', encoding="utf8")
jsonId = json.loads(file.read())
id = str(request.args.get('id'))
name = jsonId.get(id)
if name:
return str(name)
else:
return "No name found for id " + id
@app.route("/trim1bckp")
def trim1():
ipmUsername = os.environ.get('ipmUsername', None)
ipmPassword = os.environ.get('ipmPassword', None)
print(ipmUsername, ipmPassword)
r=requests.post('https://www.insignia.net.ar/ipmpadres/intranet/aspsql/verifusuario_1.asp?usuario='+ ipmUsername + '&password=' + ipmPassword)
s = requests.Session()
aluID = str(request.args.get('id'))
cookie = r.cookies.get_dict()
print(r.status_code, cookie, "pad000pre.asp" in r.text, "Session Cookies: ", s.cookies.get_dict())
if "pad000pre.asp" in str(r.content):
print("Signed In")
pad046 = requests.get("https://www.insignia.net.ar/ipmpadres/intranet/aspsql/pad046.asp?vAluSel=3918&vTrim=1", cookies=cookie)
parsed_data = lh.fromstring(str(pad046.content))
tr_elements = parsed_data.xpath('//tr')
#Create empty list
col = {}
i=0
#For each row, store each first element (header) and an empty list
json_data = {}
for t in range(5, len(tr_elements), 2):
i+=1
name=tr_elements[t].text_content().strip()
content = tr_elements[t+1].text_content().strip().replace("\n", "").replace("\t", "").replace("\r", "").replace("\xa0", " ")
if ")" in content:
col[name.strip()] = [content[content.index(")") + 1:len(content)].strip(), content[0:content.index(")") + 1].replace(" )", ")")]
else:
col[name.strip()] = [content.strip(), ""]
json_data = json.dumps(col, ensure_ascii=False).encode('utf8')
print(json_data)
backup = requests.post("https://ipmalumnstrimbackups.herokuapp.com/trim1?id=" + str(aluID) + "&data=" + str(json_data, 'utf-8'))
return json_data
else:
return {"Cannot complete the request"}
if __name__ == "__main__":
app.run(host="127.0.0.1", port=8080, debug=True)
@app.route("/getfbtrim1")
def getFbTrim1():
aluID = str(request.args.get('id'))
getFirebaseTrim1 = requests.post("https://ipmalumnstrimbackups.herokuapp.com/trim1fb?id=" + str(aluID))
return(getFirebaseTrim1.content)