repl.it
@PYer/

Widgets

Python

Replit Widgets

fork
loading
Files
  • main.py
  • create-post.txt
  • create-profile.txt
  • generatelist.txt
  • home.txt
  • widget-post.txt
  • widget-prof.txt
  • Packager files
  • poetry.lock
  • pyproject.toml
  • requirements.txt
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
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
import flask, bs4, urllib.request

app = flask.Flask('Replit Widgets')

@app.route('/')
def home():
  with open('home.txt', 'r') as homefile:
    return homefile.read()

@app.route('/generatelist')
def getdata():
  with open('generatelist.txt', 'r') as listhtml:
    return listhtml.read()

@app.route('/create-profile', methods=['GET'])
def createprofile():
  with open('create-profile.txt', 'r') as listhtml:
    if not flask.request.args.get("username"):
      return listhtml.read()
    else:
      return listhtml.read().replace("{flask-username}", flask.request.args.get("username"))

@app.route('/widget-prof', methods=['GET'])
def generateprof():
  with open('widget-prof.txt', 'r') as widgetproffile:
    widgetproftext = widgetproffile.read()
    data = ['', 'http://www.met.gov.my/content/wxicon/observation_icons/NA.png', 'Anonymous', '0', 'No Bio Set :)']
    try:
      profstr = 'https://repl.it/@' + flask.request.args.get('user')
      prof = urllib.request.urlopen(profstr)
      data[0] = profstr
      soup = bs4.BeautifulSoup(prof, 'html.parser')
      try: 
        userandcycles = soup.find('div', attrs={'class': 'profile-username-label'}).text.split()
        data[2] = userandcycles[0][1:]
        data[3] = userandcycles[1][1:-1]
      except: 
        userandcycles = soup.find('h1').text.split()
        data[2] = userandcycles[0]
        data[3] = userandcycles[1][1:-1]
      pfpspan = soup.find('span', attrs={'class': 'profile-icon-xl'})
      pfpurl = pfpspan['style'][22:-2]
      data[1] = pfpurl
      data[4] = soup.find('span', attrs={'class': 'Linkify'}).text
    except:
      data[4] = 'No bio set :)'
    widgetproftext = widgetproftext.replace('{data}', data[0], 1)
    widgetproftext = widgetproftext.replace('{data}', data[1], 1)
    widgetproftext = widgetproftext.replace('{data}', data[2], 1)
    widgetproftext = widgetproftext.replace('{data}', data[3], 1)
    widgetproftext = widgetproftext.replace('{data}', data[4], 1)
  return widgetproftext

@app.route('/create-post', methods=['GET'])
def createpost():
  with open('create-post.txt', 'r') as listhtml:
    if not flask.request.args.get("link"):
      return listhtml.read()
    else:
      return listhtml.read().replace("{flask-link}", flask.request.args.get("link"))

@app.route('/widget-post', methods=['GET'])
def generatepost():
  with open('widget-post.txt', 'r') as widgetproffile:
    widgetproftext = widgetproffile.read()
    data = ['', '32', 'Can somebody please help me thanks!', 'Post description', 'No Bio Set :)']
    '''
    try:
      profstr = 'https://repl.it/@' + flask.request.args.get('user')
      prof = urllib.request.urlopen(profstr)
      data[0] = profstr
      soup = bs4.BeautifulSoup(prof, 'html.parser')
      userandcycles = soup.find('div', attrs={'class': 'profile-username-label'}).text.split()
      data[2] = userandcycles[0][1:]
      data[3] = userandcycles[1][1:-1]
      pfpspan = soup.find('span', attrs={'class': 'profile-icon-xl'})
      pfpurl = pfpspan['style'][22:-2]
      data[1] = pfpurl
      data[4] = soup.find('span', attrs={'class': 'Linkify'}).text
    except Exception as e:
      print(e)
    '''
    widgetproftext = widgetproftext.replace('{data}', data[0], 1)
    widgetproftext = widgetproftext.replace('{data}', data[1], 1)
    widgetproftext = widgetproftext.replace('{data}', data[2], 1)
    widgetproftext = widgetproftext.replace('{data}', data[3], 1)
    widgetproftext = widgetproftext.replace('{data}', data[4], 1)
  return widgetproftext

app.run(port=9090, host='0.0.0.0')