forked from pileofscraps/wordcloud_backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
61 lines (42 loc) · 1.66 KB
/
main.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
from flask import Flask, jsonify, render_template, request
import os
import json
from web3 import Web3
import requests
from wordcloud import WordCloud
wc = WordCloud()
app = Flask(__name__)
SECRET_KEY = os.urandom(32)
app.config['SECRET_KEY'] = SECRET_KEY
# initial wordcloud_storage.txt populated with a single address: 0x5c43B1eD97e52d009611D89b74fA829FE4ac56b1 (aka pileofscraps.eth) so that the initial pong has data
@app.route('/server', methods=['GET', 'POST'])
def server():
if request.method == 'POST':
result = request.data
print(result)
result = json.loads(result)
for i in range(len(result["activity"])):
from_address = (result["activity"][i]["fromAddress"])
f = open("wordcloud_storage.txt", "a")
f.write(str(from_address)+" ")
f.close()
print("---Printing: DATA WRITE----")
text = open('wordcloud_storage.txt').read()
print(text)
return ("OK")
if request.method == 'GET':
id = request.args.get('id')
print('ID', id)
print("---Printing: DATA READ----")
text = open('wordcloud_storage.txt').read()
print(text)
wc = WordCloud(background_color="white", max_words=100)
# generate word cloud
wc.generate(text)
svg_text = wc.to_svg()
print(svg_text)
pic = {"name":"Address Rainfall 0x00","description":"Off-Chain Word Cloud Generation","image_data":str(svg_text),"attributes":[{"trait_type":"Isaac Lau","value":"One"},{"trait_type":"Adam","value":"One"},{"trait_type":"Austin","value":"One"},{"trait_type":"Xiangan","value":"One"}]}
return (pic)
#return render_template('index.html', form=form, bal=balance, block_num=block_num, total_burn=total_burn)
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')