forked from rpuneet/CPHelper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPHelper.py
More file actions
executable file
·65 lines (43 loc) · 1.73 KB
/
CPHelper.py
File metadata and controls
executable file
·65 lines (43 loc) · 1.73 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
from flask import Flask , request , redirect
import json , subprocess
import datetime
import os
PORT = 7175
def createNewTask(data):
now = datetime.datetime.now()
TEMPLATE = globalData['template']
baseContestPath = globalData['baseContestPath']
templateHeader = "/*\n"
templateHeader += 'Author : {}\n'.format(globalData['author'])
templateHeader += 'Team : {}\n'.format(globalData['teamName'])
templateHeader += '{}\n'.format(now.strftime("Date : %d-%m-%Y\nTime : %H:%M:%S"))
templateHeader += '*/\n\n'
TEMPLATE = templateHeader + TEMPLATE
taskData = json.loads(data.decode())
contestName = taskData['group']
taskName = taskData['name']
temp = ""
for x in contestName.split(' '):
temp += x
contestName = temp
temp = ""
for x in taskName.split(' '):
temp += x
taskName = temp
if not os.path.exists(os.path.join(baseContestPath , contestName , taskName + '.json')):
if not os.path.exists(os.path.join(baseContestPath , contestName)):
os.mkdir(os.path.join(baseContestPath , contestName))
with open(os.path.join(baseContestPath , contestName , taskName + '.json') , 'wb') as taskJsonFile:
taskJsonFile.write(json.dumps(taskData).encode())
with open(os.path.join(baseContestPath , contestName , taskName + '.cpp') , 'wb') as taskCppFile:
taskCppFile.write(TEMPLATE.encode())
print(subprocess.check_output(['subl' , os.path.join(baseContestPath , contestName , taskName + '.cpp')]))
globalData = {}
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)) , 'globals.json') , 'rb') as globalJsonFile:
globalData = json.loads(globalJsonFile.read().decode())
app = Flask(__name__)
@app.route('/' , methods = ['POST'])
def getData():
createNewTask(request.data)
return redirect('/')
app.run(port=PORT)