Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, request, render_template, abort, jsonify, session
- import json, hashlib, os
- app = Flask(__name__)
- app.secret_key = 'secret_key'
- matchces =
- ""
- " W3siaG9tZSI6IlN5cmlhIiwiYXdheSI6IlZpZXRuYW0iLCJzY29yZSI6IjA6MSIsImRhdGUiOiIy NyBBdWd1c3QifSx7ImhvbWUiOiJVemJla2lzdGFuIiwiYXdheSI6IlNvdXRoIEtvcmVhIiwic2Nv cmUiOiIzOjQiLCJkYXRlIjoiMjcgQXVndXN0ICJ9LAogICAgICAgICAgICAgeyJob21lIjoiU2F1 ZGkgQXJhYmlhIiwiYXdheSI6IkphcGFuIiwic2NvcmUiOiIxOjIiLCJkYXRlIjoiMjcgQXVndXN0 In0seyJob21lIjoiVW5pdGVkIEFyYWIgRW1pcmF0ZXMiLCJhd2F5IjoiTm9ydGggS29yZWEiLCJz Y29yZSI6IjE6MSIsImRhdGUiOiIyNyBBdWd1c3QifSwKICAgICAgICAgICAgIHsiaG9tZSI6ICJW aWV0bmFtIiwgImF3YXkiOiAiU291dGggS29yZWEiLCAic2NvcmUiOiAiMTozIiwgImRhdGUiOiAi MjkgQXVndXN0In0seyJob21lIjoiSmFwYW4iLCJhd2F5IjoiVW5pdGVkIEFyYWIgRW1pcmF0ZXMi LCJzY29yZSI6IjE6MCIsImRhdGUiOiIyOSBBdWd1c3QifSwKICAgICAgICAgICAgIHsiaG9tZSI6 ICJWaWV0bmFtIiwgImF3YXkiOiAiVW5pdGVkIEFyYWIgRW1pcmF0ZXMiLCAic2NvcmUiOiAiMTox IiwgImRhdGUiOiAiMSBTZXB0ZW1iZXIifSwKICAgICAgICAgICAgIHsiaG9tZSI6ICJTb3V0aCBL b3JlYSIsICJhd2F5IjogIkphcGFuIiwgInNjb3JlIjogIjI6MSIsICJkYXRlIjogIjEgU2VwdGVt YmVyIn1d "
- ""
- class Match:
- def __init__(self, _prev, home, away, score, date, id):
- self.__prev = _prev
- self.home = home
- self.home_goal = int(score[0])
- self.away_goal = int(score[2])
- self.away = away self.score = score
- self.date = date self.id = id
- def getPrev(self):
- return self.__prev
- def init():
- Matches = []
- hm = {}
- m = Match(None, None, None, "0:0", None, "123" ,if not os.path.exists("/opt/id") else open("/opt/id").read().strip())
- Matches.append(m)
- prev_hash = Matches[0].id
- hm[m.id] = m
- for match in matchces:
- match['__prev'] = prev_hash
- block_serialized = json.dumps(match, sort_keys = True).encode('utf-8')
- block_hash = hashlib.sha256(block_serialized).hexdigest()
- prev_hash = block_hash
- m = Match(match['__prev'], match['home'], match['away'], match['score'], match['date'], prev_hash)
- Matches.append(m)
- hm[prev_hash] = m
- return Matches, hm
- def checkVNvodich(rr, hm):
- try:
- rr = rr[::-1]
- r = rr[0]
- cnt = 0
- while r.home is not None:
- print r.home, r.away, r.score, r.getPrev(), r.id
- r = hm[r.getPrev()]
- cnt += 1
- if cnt > 10: #avoid infinity loop
- break
- if cnt == 8:
- if "Vietnam" == rr[0].home and rr[0].home_goal > rr[0].away_goal:
- return True
- elif "Vietnam" == rr[0].away and rr[0].home_goal < rr[0].away_goal:
- return True
- return False
- except:
- return False
- matchces = json.loads(matchces.decode('base64'))
- res, hm = init()
- @app.errorhandler(500)
- def custom500(error):
- return str(error), 500
- @app.route('/')
- def index():
- print res[0].id
- if "state" not in session.keys():
- session['state'] = res[-1].id
- else :
- if request.args.get('state') is not None and request.args.get('state') == res[0].id: #thay request.args['state'] thanh session['state'] thi co lam dc khong ?
- global matchces
- try: matchces = json.loads(request.args.get("data").decode("base64"))
- rr, hm = init()
- if checkVNvodich(rr, hm):
- return FLAG
- except:
- pass
- return render_template('index.html', res = res)
- def getInfo(match, field):
- val = getattr(match, field, None)
- if val != None:
- return val
- else :
- return "None"
- @app.route("/info/")
- def getinfo(id):
- match = None
- for r in res:
- if r.id == id:
- match = r
- break
- if "field" in request.args.keys():
- return jsonify(data = getInfo(match, request.args.get("field")))
- elif match is not None:
- return jsonify(id = match.id, home = match.home, away = match.away, score = match.score, date = match.date)
- return jsonify("No data")
- @app.route("/files/", methods = ["GET"])
- def getFile(file):
- path = app.root_path + "/" + file
- if not os.path.abspath(path).startswith(app.root_path):
- return "IFL ??"
- return open(path, 'rb').read()
- if __name__ == "__main__": app.run(host = "0.0.0.0")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement