@pieromqwerty/

Oryp Backend

Python

No description

fork
loading
Files
  • main.py
  • images
  • img_meta
  • temp
  • templates
  • api_keys.json
  • changelog.txt
  • requirements.txt

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.8820037946030974","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"ZnJvbSBmbGFzayBpbXBvcnQgRmxhc2ssIHJlbmRlcl90ZW1wbGF0ZSwgc2VuZF9maWxlLCBmbGFzaCwgcmVxdWVzdCwgcmVkaXJlY3QNCmZyb20gZmxhc2tfcmVzdGZ1bCBpbXBvcnQgQXBpLCBSZXNvdXJjZSwgcmVxcGFyc2UNCmltcG9ydCByYW5kb20NCmltcG9ydCBqc29uDQpmcm9tIG51bXB5IGltcG9ydCAqDQppbXBvcnQgb3MNCmltcG9ydCBvcy5wYXRoDQoNCiNzZXR0aW5nIHVwIGZsYXNrDQphcHAgPSBGbGFzayhfX25hbWVfXykNCmFwaSA9IEFwaShhcHApDQoNCmNsYXNzIGdldFBvc3QoUmVzb3VyY2UpOg0KCWRlZiBnZXQoc2VsZiwgaWQpOg0KCQlmaWxlbmFtZSA9ICJpbWdfbWV0YS8iICsgaWQgKyAiLmpzb24iDQoJCXByaW50KGZpbGVuYW1lKQ0KCQl0cnk6DQoJCQl3aXRoIG9wZW4oZmlsZW5hbWUsICdyJykgYXMgZmlsZWhhbmRsZTogIA0KCQkJCXBvc3RzID0ganNvbi5sb2FkKGZpbGVoYW5kbGUpDQoJCQlyZXR1cm4gcG9zdHMsIDIwMA0KCQlleGNlcHQ6DQoJCQlyZXR1cm4gIlBvc3Qgbm90IGZvdW5kIiwgNDA0DQoNCmNsYXNzIGdldEltYWdlKFJlc291cmNlKToNCglkZWYgZ2V0KHNlbGYsIGlkKToNCgkJaW1nZmlsZSA9ICJpbWFnZXMvIiArIGlkICsgIi5qcGciDQoJCXJldHVybiBzZW5kX2ZpbGUoaW1nZmlsZSkNCg0KI3JvdXRpbmcgdG8gaW5kZX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w0KYXBpLmFkZF9yZXNvdXJjZShnZXRQb3N0LCAiL2FwaS9wb3N0LzxzdHJpbmc6aWQ+IikNCmFwaS5hZGRfcmVzb3VyY2UoZ2V0SW1hZ2UsICIvYXBpL2ltYWdlLzxzdHJpbmc6aWQ+IikNCg0KI3J1bm5pbmcgd2Vic2VydmVyDQphcHAucnVuKGhvc3Q9JzAuMC4wLjAnLHBvcnQ9ODA4MCk="},"asBuffer":null},"loaded":true}}
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
from flask import Flask, render_template, send_file, flash, request, redirect
from flask_restful import Api, Resource, reqparse
import random
import json
from numpy import *
import os
import os.path

#setting up flask
app = Flask(__name__)
api = Api(app)

class getPost(Resource):
	def get(self, id):
		filename = "img_meta/" + id + ".json"
		print(filename)
		try:
			with open(filename, 'r') as filehandle:  
				posts = json.load(filehandle)
			return posts, 200
		except:
			return "Post not found", 404

class getImage(Resource):
	def get(self, id):
		imgfile = "images/" + id + ".jpg"
		return send_file(imgfile)

#routing to index page
@app.route('/')
def index():
    return render_template('index.html')

@app.route('/upload/img')
def file_uploader():
	return render_template('upload_img.html')

@app.route('/upload/meta')
def meta_uploader():
	return render_template('upload_meta.html')

@app.route('/upload/comment')
def comment_uploader():
	return render_template('upload_comment.html')

@app.route('/upload/like')
def like_uploader():
	return render_template('upload_like.html')

@app.route('/api/uploader/comment/', methods = ['POST'])
def upload_comment():
	if request.method == 'POST':
		temp = request.files['file']
		content = json.load(temp)
		print(content)
		filename = str(temp.filename)
		if filename.lower().endswith('.json'): 
			print(content['post-id'])
			try:
				print(content['post-id'])
				print('post id valid')
			except:
				return 'post id invalid'
			try:
				print(content['content'])
				print('content valid')
			except:
				return 'No Content Attatched. Terminating connection...'
			try:
				print(content['user'])
				print('user valid')
			except:
				return 'No User Attatched. Terminating connection...'
			filename = "img_meta/" + content['post-id'] + ".json"
			print(filename)
			try:
				with open(filename, 'r') as filehandle:  
					posts = json.load(filehandle)
			except:
				return 'post not found'
			print(posts)
			comments = posts['comments']
			print(comments)
			tempComm = {}
			tempid = str(len(comments))
			temp = len(tempid)
			while temp < 3:
				tempid = '0' + tempid
				temp = temp + 1
			tempComm['id'] = tempid
			tempComm['user'] = content['user']
			tempComm['content'] = content['content']
			print(tempComm)
			print(len(comments))
			comments.append(tempComm)
			posts['comments'] = comments
			print(comments)
			print(posts)
			with open(filename, 'w', encoding='utf-8') as f:
				json.dump(posts, f, ensure_ascii=False, indent=4)
			return_packet = 'file successfully uploaded with id ' + content['post-id']
			return return_packet
		else: 
			return 'incorrect file type. please upload .json'
	else:
		return 'POST method only at this endpoint'

@app.route('/api/post/like/', methods = ['POST'])
def like_Post():
	if request.method == 'POST':
		temp = request.files['file']
		content = json.load(temp)
		print(content)
		filename = str(temp.filename)
		if filename.lower().endswith('.json'): 
			print(content['post-id'])
			try:
				print(content['post-id'])
				print('post id valid')
			except:
				return 'post id invalid'
			try:
				print(content['user'])
				print('user valid')
			except:
				return 'No User Attatched. Terminating connection...'
			filename = "img_meta/" + content['post-id'] + ".json"
			print(filename)
			with open(filename) as json_data:
  				posts = json.load(json_data)
			print(posts)
			likes = posts['likes']
			print(likes)
			likes.append(content['user'])
			posts['likes'] = likes
			print(likes)
			print(posts)
			with open(filename, 'w', encoding='utf-8') as f:
				json.dump(posts, f, ensure_ascii=False, indent=4)
			return_packet = 'file successfully uploaded with id ' + content['post-id']
			return return_packet
		else: 
			return 'incorrect file type. please upload .json'
	else:
		return 'POST method only at this endpoint'

@app.route('/api/uploader/meta/', methods = ['POST'])
def upload_meta():
	if request.method == 'POST':
		temp = request.files['file']
		content = json.load(temp)
		filename = str(temp.filename)
		print(content)
		if filename.lower().endswith('.json'):
			print(content['id'])
			try:
				print(content['id'])
				print('id valid')
			except:
				return 'No ID Attatched. Terminating connection...'
			try:
				print(content['date'])
				print('date valid')
			except:
				return 'No Date Attatched. Terminating connection...'
			try:
				print(content['author'])
				print('author valid')
			except:
				return 'No Author Attatched. Terminating connection...'	
			try:
				print(content['location'])
				print('location valid')
			except:
				return 'No Location Attatched. Terminating connection...'	
			with open('img_meta/' + content['id'] + '.json', 'w', encoding='utf-8') as f:
				json.dump(content, f, ensure_ascii=False, indent=4)
			return_packet = 'file successfully uploaded with id ' + content['id']
			return return_packet
			#f.flush()
			#f.close()
			#os.fsync()
		else: 
			return 'incorrect file type. please upload .json'
	else:
		return 'POST method only at this endpoint'

@app.route('/api/uploader/img/', methods = ['POST'])
def upload_file():
	if request.method == 'POST':
		f = request.files['file']
		filename = str(f.filename)
		if filename.lower().endswith('.jpg'):
			DIR = 'images/'
			count = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))])
			dig = len(str(count))
			while dig < 12:
				count = '0' + str(count)
				dig = dig + 1
			f.save("images/" + str(count) + '.jpg')
			return str(count)
			file.flush()
			file.close()
			os.fsync()
		elif filename.lower().endswith('.png'):
			DIR = 'images/'
			count = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))])
			dig = len(str(count))
			while dig < 12:
				count = '0' + str(count)
				dig = dig + 1
			f.save("images/" + str(count) + '.jpg')
			return str(count)
			file.flush()
			file.close()
			os.fsync()
		else: 
			return 'incorrect file type. please upload .jpg'
	else:
		return 'POST method only at this endpoint'

#adding api resources
api.add_resource(getPost, "/api/post/<string:id>")
api.add_resource(getImage, "/api/image/<string:id>")

#running webserver
app.run(host='0.0.0.0',port=8080)