This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_web.py
209 lines (161 loc) · 5.19 KB
/
start_web.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
import base64
import json
from flask import Flask, render_template, request
import FaceKit
from FaceKit import function
ses = None
app = Flask(__name__)
@app.errorhandler(FaceKit.exception.CookiesInvalid)
@app.errorhandler(TypeError)
def cookies_error(error):
return json.dumps({"status": "false", "msg": "cookies invalid"})
@app.errorhandler(Exception)
def handle_error(error):
return json.dumps({"status": "false", "msg": str(error)})
@app.route("/")
def index():
return render_template("index.html", ses=ses)
@app.route("/myfriends")
def myfriend():
next_ = request.args.get("next")
if next:
try:
next_ = base64.b64decode(next_.encode()).decode()
except:
next_ = None
data = FaceKit.myFriend(ses, next=next_)
next_ = None if not data.next else base64.b64encode(data.next.encode()).decode()
# print(next_)
return render_template("myfriends.html", ses=ses, items=data.items, next=next_)
@app.route("/mygroups")
def mygroups():
data = FaceKit.myGroup(ses)
return render_template("mygroups.html", ses=ses, items=data.items)
@app.route("/reaction/<in_>")
def reaction(in_):
id_ = request.args.get("id")
# print(id_)
if in_ == "hm":
return render_template("react_hm.html")
elif in_ == "ft":
return render_template("react_ft.html", id_=id_)
elif in_ == "gr":
return render_template("react_gr.html", id_=id_)
elif in_ == "fp":
return render_template("react_fp.html")
else:
raise Exception(
"404 Not Found: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again."
)
@app.route("/comment/<in_>")
def comment(in_):
id_ = request.args.get("id")
if in_ == "hm":
return render_template("comment_hm.html")
elif in_ == "ft":
return render_template("comment_ft.html", id_=id_)
elif in_ == "gr":
return render_template("comment_gr.html", id_=id_)
elif in_ == "fp":
return render_template("comment_fp.html")
else:
raise Exception(
"404 Not Found: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again."
)
@app.route("/mass/<menu>")
def mass_menu(menu):
if menu == "unfriend":
title = "Mass Unfriend"
func_dump = "myFriend"
index_id = 1
method = "GET"
func_process = "unfriend"
elif menu == "accept-friend":
title = "Mass Accept Friend Request"
func_dump = "friend_request"
index_id = 0
method = "POST"
func_process = "open_url"
elif menu == "reject-friend":
title = "Mass Reject Friend Request"
func_dump = "friend_request"
index_id = 1
method = "POST"
func_process = "open_url"
elif menu == "unadd":
title = "Mass Unadd"
func_dump = "friend_requested"
index_id = ""
method = "POST"
func_process = "open_url"
return render_template(
"mass_template.html",
title=title,
func_dump=func_dump,
index_id=index_id,
method=method,
func_process=func_process,
)
@app.route("/function")
def func():
return ""
@app.route("/function/open_url", methods=["POST"])
def open_url():
url = request.form["id"]
ses.session.get(url)
return json.dumps({"status": True})
@app.route("/function/unfriend")
def unfriend_gas():
id_ = request.args.get("id")
if not id_:
return json.dumps({"status": False})
data = function.unfriend(ses, id_)
return json.dumps({"status": data.status})
@app.route("/function/leave")
def leave_group():
id_ = request.args.get("id")
if not id_:
return json.dumps({"status": False})
data = function.leave_group(ses, id_)
return json.dumps({"status": data.status})
@app.route("/function/dump")
def dump():
func = request.args.get("func")
limit = request.args.get("limit")
if limit is None or int(limit) < 0:
limit = 10
kwargs = request.args.copy()
del kwargs["func"]
if request.args.get("limit") != None:
del kwargs["limit"]
func = eval(f"FaceKit.{func}")
data = func(ses, **kwargs)
kwargs["next"] = data.next
if data.next:
data_ = function.dump(func, args=(ses,), kwargs=kwargs, limit=int(limit))
else:
data_ = []
data_ = data.items + data_
rv = {
"status": True,
"title": data.bs4().find("title").text,
"items": data_[: int(limit)],
}
return json.dumps(rv)
@app.route("/function/reaction", methods=["POST"])
def give_react():
url = request.form["url"]
type_ = request.form["type"]
data = function.react(ses, url, type=type_)
# print()
return json.dumps({"status": data.status})
@app.route("/function/comment", methods=["POST"])
def give_comment():
url = request.form["url"]
comment_value = request.form["comment_value"]
data = function.comment(ses, url, comment_value)
return json.dumps({"status": data.status})
@app.route("/function/search_f")
def search_f():
name = request.args["name"]
return json.dumps(FaceKit.find_id_friend(ses, name))