This repository was archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.py
More file actions
137 lines (98 loc) · 3.36 KB
/
application.py
File metadata and controls
137 lines (98 loc) · 3.36 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import json
import pathlib
import warnings
import os
import shutil
from time import strftime, gmtime, sleep
from urllib.request import urlopen
import core_api_types.classes as CoreClasses
import core_api_types.namespaces as CoreNamespaces
import core_api_types.enums as CoreEnums
from git import Repo
CORE_API_URL = "https://docs.coregames.com/assets/api/CoreLuaAPI.json"
FILE_DUMP_TEXT = "internal_dumps/core_api_dump.txt"
FILE_DUMP_JSON = "internal_dumps/core_api_dump.json"
COMMIT_MESSAGE = "Update to Core API: %s"
repository = Repo(str(pathlib.Path().absolute()))
origin = repository.remote(name='origin')
with repository.config_writer() as git_config:
git_config.set_value('user', 'email', 'nicholas.w.foreman@outlook.com')
git_config.set_value('user', 'name', 'azutreo')
def PushToRepository(datetimeGMT):
try:
repository.git.add(A=True)
repository.index.commit(COMMIT_MESSAGE % datetimeGMT)
origin.pull()
origin.push()
except Exception as e:
warnings.warn(e, UserWarning)
else:
print("Successfully pushed changes: " + datetimeGMT)
def GetFileContents(filename):
file = open(filename, "r")
contents = file.read()
file.close()
return contents
def IsSame(dump):
contents = GetFileContents(FILE_DUMP_TEXT)
return dump == contents
def WriteDumpText(contents):
textDump = open(FILE_DUMP_TEXT, "w+")
textDump.write(contents)
textDump.close()
def GetJsonParsedData(content):
# data = content.decode("UTF-8")
return json.loads(content)
def Main():
# See if the API has changed AT ALL
response = urlopen(CORE_API_URL)
pageContents = response.read().decode("UTF-8")
if IsSame(pageContents):
return
WriteDumpText(pageContents)
# Grab the old/new json required for comparisons
newJsonData = json.loads(pageContents)
oldJsonText = GetFileContents(FILE_DUMP_JSON)
oldJsonData = json.loads(oldJsonText)
# DIFFERENCES IN CLASSES
classDifferences = CoreClasses.GetDifferences(newJsonData, oldJsonData)
classSequence = []
for classDifference in classDifferences:
classSequence.append(classDifference + "\n")
if len(classSequence) >= 1:
classSequence.append("\n")
# DIFFERENCES IN NAMESPACES
namespaceDifferences = CoreNamespaces.GetDifferences(newJsonData, oldJsonData)
namespaceSequence = []
for namespaceDifference in namespaceDifferences:
namespaceSequence.append(namespaceDifference + "\n")
if len(namespaceSequence) >= 1:
namespaceSequence.append("\n")
# DIFFERENCES IN ENUMS
enumDifferences = CoreEnums.GetDifferences(newJsonData, oldJsonData)
enumSequence = []
for enumDifference in enumDifferences:
enumSequence.append(enumDifference + "\n")
# Current Time
datetimeGMT = strftime("%Y-%m-%d", gmtime())
# Create differences file
differencesTextFile = open("differences/" + datetimeGMT + ".txt", "w+")
differencesTextFile.writelines(classSequence + namespaceSequence + enumSequence)
differencesTextFile.close()
# Create a dump into api_dumps
newJsonFile = open("api_dumps/" + datetimeGMT + ".json", "w+")
newJsonFile.write(pageContents)
newJsonFile.close()
# Set the "new" to be what was grabbed from online
newJsonFile = open(FILE_DUMP_JSON, "w+")
newJsonFile.write(pageContents)
newJsonFile.close()
PushToRepository(datetimeGMT)
if __name__ == "__main__":
print("Running program; close to cancel (Ctrl + C if in console)")
Main()
try:
while sleep(60):
Main()
except(KeyboardInterrupt):
print("Cancelled program")