-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaodao.py
290 lines (251 loc) · 11.2 KB
/
daodao.py
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#-*- coding:UTF-8 -*-
#@update:2022/9/7
#@update:2022/9/8
# TODO:提交PR
from re import S
from unittest import expectedFailure
from urllib.error import URLError
import requests
import json
import time
from datetime import date,timedelta
import os
import sys
import urllib
from colorama import init, Fore, Back, Style
init(autoreset=True)
class Colored(object):
def red(self, s):
return Fore.RED + s + Fore.RESET
def green(self, s):
return Fore.GREEN + s + Fore.RESET
def yellow(self, s):
return Fore.YELLOW + s + Fore.RESET
def blue(self, s):
return Fore.BLUE + s + Fore.RESET
def magenta(self, s):
return Fore.MAGENTA + s + Fore.RESET
def cyan(self, s):
return Fore.CYAN + s + Fore.RESET
def white(self, s):
return Fore.WHITE + s + Fore.RESET
def black(self, s):
return Fore.BLACK
def white_green(self, s):
return Fore.WHITE + Back.GREEN + s + Fore.RESET + Back.RESET
def helloToUser():
print("""
____ _ ____ _
| _ \ __ _ ___ __| | __ _ ___ | __ ) __ _ ___| |__
| | | |/ _` |/ _ \ / _` |/ _` |/ _ \ | _ \ / _` / __| '_ \\
| |_| | (_| | (_) | (_| | (_| | (_) | | |_) | (_| \__ \ | | |
|____/ \__,_|\___/ \__,_|\__,_|\___/ |____/ \__,_|___/_| |_|
--@update:2022/9/8 --you need python3.8+
""")
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.green('INFO'),"]","Please use a bigger bash window")
print(color.magenta('Version alpha 0.7.0 Powered by JiuLER & lamaper'))
def checkUrl(): # 检查Url可用性
try:
r = requests.get('https://api.c12th.eu.org/')
if r.status_code != 200:
return 2
except:
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.red('ERROR'),"]",'Check your internet!')
sys.exit()
if magicFirst == True:
return
try:
r1 = requests.get(url+'c=DaoDaoBash_LoginCheck'+'&k='+password)
if r1.status_code == 200 and r1.text == 'Execution: you did not send a message today, create an issue and add a comment!':
requests.get(url+'dn=1'+'&k='+password)
except:
return 2
def autoLogin():
global isAutoLogin
global magicChain
global username
global password
global url
with open('log', 'r') as logfile:
try:
magicChain = logfile.read()
except:
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.red('ERROR'),"]",'Check your log!')
if magicChain == "":
isAutoLogin == False
else:
username = magicChain[:magicChain.find(chr(36))]
password = magicChain[magicChain.find(chr(36))+1:magicChain.find(chr(38))]
url = magicChain[magicChain.find(chr(38))+1:]
isAutoLogin = True
logfile.close()
def inputInfo():
global username
global password
global url
global yoururl
global magicChain
global isAutoLogin
username = ""
magicCheck = 0
while True:
if isAutoLogin == False:
yoururl = input("[YourUrl]:")
username = input("[UserName]:")
password = input("[Password]:")
url = f'http://{urllib.parse.urlparse(yoururl).netloc}/api/?'
magicCheck = checkUrl()
if isAutoLogin == True:
autoLogin()
if magicCheck == 2:
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.red('ERROR'),"]",'Check your url!')
os.system("exit()")
elif magicCheck != 2 and username != "" and password != "":
with open('log', 'w') as file:
magicChain = username + chr(36) + password + chr(38) + url
file.write(magicChain)
file.close()
break
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.red('ERROR'),"]",'Check your internet or your password!')
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.red('ERROR'),"]",'If you want to exit,please press \'CTRL\'+\'C\'')
def checkIntn():
try:
r = requests.get('https://api.c12th.eu.org/')
if r.status_code != 200:
return 2
except:
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.red('ERROR'),"]",'Check your internet!')
sys.exit()
def workInWhile():
global auto
global isAutoLogin
global magicChain
userBash = f"[$root / @{username}]>> "
while True:
opt = input(userBash)
# print("8798982949\n")
if opt == 'help':
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.green('OPTIONS'),"]",)
print('查询:query\n发布:commit\n删除:delete\n编辑:edit\n清屏:clear\n设置自动登录:auto')
elif opt == 'query' or opt == 'q':
checkIntn()
id = input("The size is: ")
r = requests.get(url+'q='+str(id))
if r.status_code == 200:
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.green('STATUE'),"]",'Success!')
ret = json.loads(r.text)
# print(ret)
for i in range(len(ret)):
now = ret[i]['date']['$date']
# print(now)
timeArray = time.localtime(now)
print("[",color.green('INFO'),"]","NO.", i + 1)
print("[",color.green('INFO'),"]","time:", time.strftime("%Y-%m-%d %H:%M:%S", timeArray))
print("[",color.green('INFO'),"]","from:", ret[i]['from'])
print("[",color.green('INFO'),"]","content:", ret[i]['content'])
print()
else:
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.red('ERROR'),"]",'Check your internet!')
elif opt == 'commit' or opt == 'c':
checkIntn()
content = input("You want to daodao >> ")
r = requests.get(url+'c='+str(content)+'&k='+password)
if r.status_code == 200:
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.green('INFO'),"]",'Success!')
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.green('INFO'),"]",'You have already create a new daodao!')
# ret = r.content.decode('utf-8')
# print(ret)
else:
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.red('ERROR'),"]",'Check your internet!')
print()
elif opt == 'delete' or opt == 'd':
checkIntn()
id = input("The number you want to delete is >> ")
r = requests.get(url+'dn='+str(id)+'&k='+password)
if r.status_code == 200:
# print('Success!')
ret = r.content.decode('utf-8')
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.green('INFO'),"]")
print(ret)
else:
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.red('ERROR'),"]",'Check your internet!')
print()
elif opt == 'edit' or opt == 'e':
checkIntn()
id = input("The number you want to edit is >> ")
content = input("You want to replace >> ")
r = requests.get(url+'e='+str(id)+','+content+'&k='+password)
if r.status_code == 200:
ret = r.content.decode('utf-8')
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.green('INFO'),"]",ret)
else:
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.red('ERROR'),"]",'Check your internet!')
print()
elif opt == 'clear':
os.system("cls")
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.blue('BASH'),"]","Successfully cleared!")
elif opt == 'exit':
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.blue('BASH'),"]","Successfully exited!")
sys.exit()
elif opt == 'auto':
text1 = f"please input statue (Y/N),now the autoLogin is {isAutoLogin}"
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.green('INFO'),"]",text1)
while True:
oop = input(">> ")
if oop == "Y" or oop == "y":
isAutoLogin = True
with open('log', 'w') as f:
# print(magicChain)
f.write(magicChain)
f.close()
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.yellow('WARNING'),"]","AutoLogin statue has been changed successfully!")
break
elif oop == "N" or oop == "n":
isAutoLogin = False
with open('log', 'w') as f:
f.truncate()
f.close()
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.yellow('WARNING'),"]","fine.")
break
else:
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.red('ERROR'),"]",'Check your input!')
break
# elif opt == ''
else:
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.yellow('WARNING'),"]","The command \'",opt,"\' is not exist!")
if __name__ == "__main__":
global username
global password
global url
global yoururl
global isAutoLogin
global magicChain
global color
global magicFirst
global auto
name = ""
password = ""
yoururl = ""
url = ""
magicChain = ""
isAutoLogin = False
magicFirst = True
try:
f = open('log', 'x')
f.close()
except:
pass
color = Colored()
helloToUser()
autoLogin()
checkUrl()
if isAutoLogin == False:
print(color.magenta('You Need to Login!\n'))
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.yellow('WARNING'),"]",color.yellow("Enter a URL related to your Daodao for operation, and you can cancel it if you want!"))
magicFirst = False
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.yellow('WARNING'),"]","Your autoLogin is",isAutoLogin,"!")
inputInfo()
print('\n[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.green('INFO'),"]","Internet has connected successfully!")
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.blue('WELCOME'),"]","Let's enjoy it now!")
print('[',time.strftime('%H:%M:%S',time.localtime()),']',"[",color.blue('WELCOME'),"]","input 'help' to know how to use it...")
workInWhile()