commit
7e172664b6
Binary file not shown.
After Width: | Height: | Size: 6.9 KiB |
222
tildr/main.py
222
tildr/main.py
|
@ -4,17 +4,17 @@ ___name___ = "Tildr Dating"
|
||||||
___license___ = "MIT"
|
___license___ = "MIT"
|
||||||
___dependencies___ = ["wifi", "http", "ugfx_helper", "sleep", "dialogs", "sim800", "database"]
|
___dependencies___ = ["wifi", "http", "ugfx_helper", "sleep", "dialogs", "sim800", "database"]
|
||||||
___categories___ = ["Other"]
|
___categories___ = ["Other"]
|
||||||
___bootstrapped___ = True
|
___bootstrapped___ = False
|
||||||
|
|
||||||
import app, buttons, ugfx, ugfx_helper, http, dialogs, sim800, database, ujson, ure
|
import app, buttons, ugfx, ugfx_helper, sleep, http, dialogs, sim800, database, ujson
|
||||||
from tilda import Buttons
|
from tilda import Buttons
|
||||||
from machine import Neopix
|
|
||||||
|
|
||||||
running = True
|
from tildr.profile import get_profile
|
||||||
|
from tildr.shared import clear
|
||||||
|
from tildr import splash, profile, person, nomore
|
||||||
|
|
||||||
api_url = "http://emf2018.us-east-2.elasticbeanstalk.com"
|
api_url = "http://emf2018.us-east-2.elasticbeanstalk.com"
|
||||||
|
|
||||||
n = Neopix()
|
|
||||||
|
|
||||||
ugfx_helper.init()
|
ugfx_helper.init()
|
||||||
ugfx.clear(ugfx.html_color(0x000000))
|
ugfx.clear(ugfx.html_color(0x000000))
|
||||||
|
|
||||||
|
@ -23,183 +23,63 @@ style.set_enabled([ugfx.WHITE, ugfx.WHITE, ugfx.html_color(0x888888), ugfx.html_
|
||||||
style.set_background(ugfx.html_color(0x000000))
|
style.set_background(ugfx.html_color(0x000000))
|
||||||
ugfx.set_default_style(style)
|
ugfx.set_default_style(style)
|
||||||
|
|
||||||
def render_splash_screen():
|
def error_screen(state):
|
||||||
ugfx.clear(ugfx.html_color(0x000000))
|
ugfx.text(5, 100, "Error: try again later :(", ugfx.WHITE)
|
||||||
try:
|
|
||||||
logo = http.get("https://i.imgur.com/0TjxEPs.png").raise_for_status().content
|
|
||||||
ugfx.display_image(
|
|
||||||
int((ugfx.width() - 164)/2),
|
|
||||||
20,
|
|
||||||
bytearray(logo))
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
ugfx.text(160, 100, "TILDR", ugfx.WHITE)
|
def error_actions(state):
|
||||||
ugfx.text(0, 270, "Find your match @emfcamp ;)", ugfx.WHITE)
|
|
||||||
ugfx.text(45, 300, "Press A to begin", ugfx.WHITE)
|
|
||||||
|
|
||||||
|
|
||||||
def run_splash_screen():
|
|
||||||
while True:
|
|
||||||
if buttons.is_triggered(Buttons.BTN_Menu):
|
|
||||||
return False
|
|
||||||
if buttons.is_triggered(Buttons.BTN_A):
|
if buttons.is_triggered(Buttons.BTN_A):
|
||||||
return True
|
state['next'] = "SPLASH"
|
||||||
|
|
||||||
def create_profile(my_profile):
|
screens = {
|
||||||
ugfx.clear(ugfx.html_color(0x000000))
|
'SPLASH': {'render': splash.screen, 'actions': splash.actions},
|
||||||
|
'PROFILE': {'render': profile.screen, 'actions': profile.actions},
|
||||||
name, age = "", ""
|
'ERROR': {'render': error_screen, 'actions': error_actions},
|
||||||
while name == "":
|
'NEXT_PERSON': {'render': person.screen, 'actions': person.actions},
|
||||||
name = dialogs.prompt_text("What's your name?")
|
'NO_MORE': {'render': nomore.screen, 'actions': nomore.actions}
|
||||||
while age == "":
|
|
||||||
age = dialogs.prompt_text("What's your age?")
|
|
||||||
tag_line = dialogs.prompt_text("Tell us your tagline:")
|
|
||||||
looking_for = dialogs.prompt_text("And what you're looking for:")
|
|
||||||
contact = dialogs.prompt_text("And your twitter username?")
|
|
||||||
imei = sim800.imei()
|
|
||||||
|
|
||||||
top_left_logo()
|
|
||||||
ugfx.text(5, 100, "Working...", ugfx.BLACK)
|
|
||||||
|
|
||||||
profile = {
|
|
||||||
'unique_identifier': imei,
|
|
||||||
'username': name,
|
|
||||||
'age': age,
|
|
||||||
'tag_line': tag_line,
|
|
||||||
'looking_for': looking_for,
|
|
||||||
'contact': contact
|
|
||||||
}
|
}
|
||||||
|
|
||||||
profile_json = ujson.dumps(profile)
|
state = {
|
||||||
|
'api': api_url,
|
||||||
|
'running': True,
|
||||||
|
'screen': None,
|
||||||
|
'next': "SPLASH",
|
||||||
|
'ui': [],
|
||||||
|
'profile': None
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def destroy(state):
|
||||||
|
for item in state['ui']:
|
||||||
try:
|
try:
|
||||||
http.post(api_url+'/create_user', json=profile).raise_for_status().close()
|
item.hide()
|
||||||
except:
|
|
||||||
ugfx.clear()
|
|
||||||
ugfx.text(5, 100, "Error. Try again later. :(", ugfx.BLACK)
|
|
||||||
return False
|
|
||||||
|
|
||||||
database.set("tildr_profile", profile_json)
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def main_screen(my_profile):
|
|
||||||
while True:
|
|
||||||
next_person(my_profile)
|
|
||||||
while True:
|
|
||||||
if buttons.is_triggered(Buttons.BTN_Menu):
|
|
||||||
return False
|
|
||||||
if buttons.is_triggered(Buttons.BTN_B) or buttons.is_triggered(Buttons.JOY_Right):
|
|
||||||
break
|
|
||||||
# if buttons.is_triggered(Buttons.BTN_A) or buttons.is_triggered(Buttons.JOY_Left):
|
|
||||||
# create_profile(my_profile)
|
|
||||||
# break
|
|
||||||
|
|
||||||
|
|
||||||
def next_person(my_profile):
|
|
||||||
ugfx.clear(ugfx.html_color(0x000000))
|
|
||||||
ugfx.text(5, 100, "Loading...", ugfx.WHITE)
|
|
||||||
try:
|
|
||||||
resp = http.get(api_url+'/get_user/'+my_profile['unique_identifier']).json()
|
|
||||||
except:
|
|
||||||
ugfx.clear()
|
|
||||||
ugfx.text(5, 100, "Error. Try again later. :(", ugfx.BLACK)
|
|
||||||
return
|
|
||||||
|
|
||||||
if resp['success']:
|
|
||||||
display_person(resp['value'])
|
|
||||||
else:
|
|
||||||
no_more(my_profile)
|
|
||||||
|
|
||||||
|
|
||||||
def display_person(person):
|
|
||||||
top_left_logo()
|
|
||||||
|
|
||||||
# try:
|
|
||||||
# resp = http.get("https://twitter.com/"+person['contact'].lstrip("@")+"/profile_image?size=mini").raise_for_status()
|
|
||||||
# url2 = ure.search('href=\"([^\"]+)',resp.content).group(1).decode('ascii')
|
|
||||||
# print(url2)
|
|
||||||
# img = http.get(url2).raise_for_status().content
|
|
||||||
# print(img)
|
|
||||||
# ugfx.display_image(180, 5, bytearray(img))
|
|
||||||
# except Exception as ex:
|
|
||||||
# print(ex)
|
|
||||||
|
|
||||||
ugfx.set_default_font(ugfx.FONT_TITLE)
|
|
||||||
ugfx.Label(5, 90, 230, 40, person["username"], justification=ugfx.Label.LEFTTOP)
|
|
||||||
ugfx.set_default_font(ugfx.FONT_SMALL)
|
|
||||||
ugfx.text(200, 92, person["age"], ugfx.WHITE)
|
|
||||||
|
|
||||||
ugfx.Label(5, 120, 230, 60, person["tag_line"])
|
|
||||||
|
|
||||||
ugfx.Label(5, 200, 230, 40, person["looking_for"])
|
|
||||||
ugfx.text(5, 190, "Looking for...", ugfx.RED)
|
|
||||||
|
|
||||||
ugfx.text(5, 245, person["contact"], ugfx.BLUE)
|
|
||||||
|
|
||||||
# ugfx.Button(0, 280, 100, 40, "< Edit profile", parent=None, shape=ugfx.Button.RECT, style=None)
|
|
||||||
ugfx.Button(160, 280, 100, 40, "Swipe >", parent=None, shape=ugfx.Button.RECT, style=None)
|
|
||||||
|
|
||||||
|
|
||||||
def no_more(my_profile):
|
|
||||||
top_left_logo()
|
|
||||||
|
|
||||||
ugfx.set_default_font(ugfx.FONT_TITLE)
|
|
||||||
ugfx.Label(5, 90, 230, 50, "You've swiped everybody!", justification=ugfx.Label.CENTERTOP)
|
|
||||||
ugfx.set_default_font(ugfx.FONT_SMALL)
|
|
||||||
ugfx.Label(5, 160, 230, 20, "Soz "+my_profile["username"], justification=ugfx.Label.CENTERTOP)
|
|
||||||
ugfx.Label(5, 180, 230, 20, "Come back later ;)", justification=ugfx.Label.CENTERTOP)
|
|
||||||
|
|
||||||
# ugfx.Button(0, 280, 100, 40, "< Edit profile", parent=None, shape=ugfx.Button.RECT, style=None)
|
|
||||||
ugfx.Button(160, 280, 100, 40, "Try again >", parent=None, shape=ugfx.Button.RECT, style=None)
|
|
||||||
|
|
||||||
|
|
||||||
def get_profile():
|
|
||||||
profile_json = database.get("tildr_profile")
|
|
||||||
if profile_json is None:
|
|
||||||
return None
|
|
||||||
|
|
||||||
profile = ujson.loads(profile_json)
|
|
||||||
return profile
|
|
||||||
|
|
||||||
|
|
||||||
def top_left_logo():
|
|
||||||
ugfx.clear(ugfx.html_color(0x000000))
|
|
||||||
try:
|
|
||||||
logo = http.get("https://i.imgur.com/5HXmXBU.png").raise_for_status().content
|
|
||||||
ugfx.display_image(0, 5, bytearray(logo))
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
item.destroy()
|
||||||
|
|
||||||
|
state['ui'] = []
|
||||||
|
|
||||||
|
|
||||||
def quit_loop():
|
state['profile'] = get_profile()
|
||||||
while True:
|
|
||||||
|
while state['running']:
|
||||||
|
|
||||||
|
# Move to next screen
|
||||||
|
if state['next']:
|
||||||
|
destroy(state)
|
||||||
|
nxt = state['next']
|
||||||
|
state['screen'] = nxt
|
||||||
|
state['next'] = None
|
||||||
|
|
||||||
|
clear()
|
||||||
|
screens[nxt]['render'](state)
|
||||||
|
|
||||||
|
sleep.wfi()
|
||||||
|
|
||||||
|
s = state['screen']
|
||||||
|
screens[s]['actions'](state)
|
||||||
|
|
||||||
if buttons.is_triggered(Buttons.BTN_Menu):
|
if buttons.is_triggered(Buttons.BTN_Menu):
|
||||||
return False
|
state['running'] = False
|
||||||
|
|
||||||
|
|
||||||
while running:
|
|
||||||
|
|
||||||
profile = get_profile()
|
|
||||||
|
|
||||||
if profile is None:
|
|
||||||
render_splash_screen()
|
|
||||||
if not run_splash_screen():
|
|
||||||
break
|
|
||||||
profile = {
|
|
||||||
'username': "",
|
|
||||||
'age': "",
|
|
||||||
'tag_line': "",
|
|
||||||
'looking_for': "",
|
|
||||||
'contact': ""
|
|
||||||
}
|
|
||||||
if not create_profile(profile):
|
|
||||||
continue
|
|
||||||
|
|
||||||
main_screen(profile)
|
|
||||||
if not quit_loop():
|
|
||||||
break
|
|
||||||
|
|
||||||
app.restart_to_default()
|
app.restart_to_default()
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
import ugfx, buttons
|
||||||
|
from tilda import Buttons
|
||||||
|
from tildr.shared import top_left_logo
|
||||||
|
|
||||||
|
def screen(state):
|
||||||
|
window = ugfx.Container(0, 0, 240, 320)
|
||||||
|
window.show()
|
||||||
|
|
||||||
|
top_left_logo()
|
||||||
|
|
||||||
|
ugfx.set_default_font(ugfx.FONT_TITLE)
|
||||||
|
l1 = ugfx.Label(5, 90, 230, 50, "You've swiped everybody!", parent=window, justification=ugfx.Label.CENTERTOP)
|
||||||
|
ugfx.set_default_font(ugfx.FONT_SMALL)
|
||||||
|
l2 = ugfx.Label(5, 160, 230, 20, "Soz "+state["profile"]["username"], parent=window, justification=ugfx.Label.CENTERTOP)
|
||||||
|
l3 = ugfx.Label(5, 180, 230, 20, "Come back later ;)", parent=window, justification=ugfx.Label.CENTERTOP)
|
||||||
|
|
||||||
|
b2 = ugfx.Button(0, 280, 120, 40, "< Edit profile", parent=window, shape=ugfx.Button.RECT, style=None)
|
||||||
|
b1 = ugfx.Button(120, 280, 120, 40, "Try again >", parent=window, shape=ugfx.Button.RECT, style=None)
|
||||||
|
|
||||||
|
state['ui'].append(window)
|
||||||
|
state['ui'].append(l1)
|
||||||
|
state['ui'].append(l2)
|
||||||
|
state['ui'].append(l3)
|
||||||
|
state['ui'].append(b1)
|
||||||
|
state['ui'].append(b2)
|
||||||
|
|
||||||
|
|
||||||
|
def actions(state):
|
||||||
|
if buttons.is_triggered(Buttons.BTN_B) or buttons.is_triggered(Buttons.JOY_Right):
|
||||||
|
state['next'] = "NEXT_PERSON"
|
||||||
|
if buttons.is_triggered(Buttons.BTN_A) or buttons.is_triggered(Buttons.JOY_Left):
|
||||||
|
state['next'] = "PROFILE"
|
|
@ -0,0 +1,163 @@
|
||||||
|
|
||||||
|
def render_splash_screen():
|
||||||
|
ugfx.clear(ugfx.html_color(0x000000))
|
||||||
|
try:
|
||||||
|
logo = http.get("https://i.imgur.com/0TjxEPs.png").raise_for_status().content
|
||||||
|
ugfx.display_image(
|
||||||
|
int((ugfx.width() - 164)/2),
|
||||||
|
20,
|
||||||
|
bytearray(logo))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
ugfx.text(160, 100, "TILDR", ugfx.WHITE)
|
||||||
|
ugfx.text(0, 270, "Find your match @emfcamp ;)", ugfx.WHITE)
|
||||||
|
ugfx.text(45, 300, "Press A to begin", ugfx.WHITE)
|
||||||
|
|
||||||
|
|
||||||
|
def run_splash_screen():
|
||||||
|
while True:
|
||||||
|
if buttons.is_triggered(Buttons.BTN_Menu):
|
||||||
|
return False
|
||||||
|
if buttons.is_triggered(Buttons.BTN_A):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def create_profile(my_profile):
|
||||||
|
ugfx.clear(ugfx.html_color(0x000000))
|
||||||
|
|
||||||
|
name, age = "", ""
|
||||||
|
while name == "":
|
||||||
|
name = dialogs.prompt_text("What's your name?")
|
||||||
|
while age == "":
|
||||||
|
age = dialogs.prompt_text("What's your age?")
|
||||||
|
tag_line = dialogs.prompt_text("Tell us your tagline:")
|
||||||
|
looking_for = dialogs.prompt_text("And what you're looking for:")
|
||||||
|
contact = dialogs.prompt_text("And your twitter username?")
|
||||||
|
imei = sim800.imei()
|
||||||
|
|
||||||
|
top_left_logo()
|
||||||
|
ugfx.text(5, 100, "Working...", ugfx.BLACK)
|
||||||
|
|
||||||
|
profile = {
|
||||||
|
'unique_identifier': imei,
|
||||||
|
'username': name,
|
||||||
|
'age': age,
|
||||||
|
'tag_line': tag_line,
|
||||||
|
'looking_for': looking_for,
|
||||||
|
'contact': contact
|
||||||
|
}
|
||||||
|
|
||||||
|
profile_json = ujson.dumps(profile)
|
||||||
|
|
||||||
|
try:
|
||||||
|
http.post(api_url+'/create_user', json=profile).raise_for_status().close()
|
||||||
|
except:
|
||||||
|
ugfx.clear()
|
||||||
|
ugfx.text(5, 100, "Error. Try again later. :(", ugfx.BLACK)
|
||||||
|
return False
|
||||||
|
|
||||||
|
database.set("tildr_profile", profile_json)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def main_screen(my_profile):
|
||||||
|
while True:
|
||||||
|
next_person(my_profile)
|
||||||
|
while True:
|
||||||
|
if buttons.is_triggered(Buttons.BTN_Menu):
|
||||||
|
return False
|
||||||
|
if buttons.is_triggered(Buttons.BTN_B) or buttons.is_triggered(Buttons.JOY_Right):
|
||||||
|
break
|
||||||
|
# if buttons.is_triggered(Buttons.BTN_A) or buttons.is_triggered(Buttons.JOY_Left):
|
||||||
|
# create_profile(my_profile)
|
||||||
|
# break
|
||||||
|
|
||||||
|
|
||||||
|
def next_person(my_profile):
|
||||||
|
ugfx.clear(ugfx.html_color(0x000000))
|
||||||
|
ugfx.text(5, 100, "Loading...", ugfx.WHITE)
|
||||||
|
try:
|
||||||
|
resp = http.get(api_url+'/get_user/'+my_profile['unique_identifier']).json()
|
||||||
|
except:
|
||||||
|
ugfx.clear()
|
||||||
|
ugfx.text(5, 100, "Error. Try again later. :(", ugfx.BLACK)
|
||||||
|
return
|
||||||
|
|
||||||
|
if resp['success']:
|
||||||
|
display_person(resp['value'])
|
||||||
|
else:
|
||||||
|
no_more(my_profile)
|
||||||
|
|
||||||
|
|
||||||
|
def display_person(person):
|
||||||
|
top_left_logo()
|
||||||
|
|
||||||
|
ugfx.set_default_font(ugfx.FONT_TITLE)
|
||||||
|
ugfx.Label(5, 90, 230, 40, person["username"], justification=ugfx.Label.LEFTTOP)
|
||||||
|
ugfx.set_default_font(ugfx.FONT_SMALL)
|
||||||
|
ugfx.text(200, 92, person["age"], ugfx.WHITE)
|
||||||
|
|
||||||
|
ugfx.Label(5, 120, 230, 60, person["tag_line"])
|
||||||
|
|
||||||
|
ugfx.Label(5, 200, 230, 40, person["looking_for"])
|
||||||
|
ugfx.text(5, 190, "Looking for...", ugfx.RED)
|
||||||
|
|
||||||
|
ugfx.text(5, 245, person["contact"], ugfx.BLUE)
|
||||||
|
|
||||||
|
# ugfx.Button(0, 280, 100, 40, "< Edit profile", parent=None, shape=ugfx.Button.RECT, style=None)
|
||||||
|
ugfx.Button(160, 280, 100, 40, "Swipe >", parent=None, shape=ugfx.Button.RECT, style=None)
|
||||||
|
|
||||||
|
|
||||||
|
def no_more(my_profile):
|
||||||
|
top_left_logo()
|
||||||
|
|
||||||
|
ugfx.set_default_font(ugfx.FONT_TITLE)
|
||||||
|
ugfx.Label(5, 90, 230, 50, "You've swiped everybody!", justification=ugfx.Label.CENTERTOP)
|
||||||
|
ugfx.set_default_font(ugfx.FONT_SMALL)
|
||||||
|
ugfx.Label(5, 160, 230, 20, "Soz "+my_profile["username"], justification=ugfx.Label.CENTERTOP)
|
||||||
|
ugfx.Label(5, 180, 230, 20, "Come back later ;)", justification=ugfx.Label.CENTERTOP)
|
||||||
|
|
||||||
|
# ugfx.Button(0, 280, 100, 40, "< Edit profile", parent=None, shape=ugfx.Button.RECT, style=None)
|
||||||
|
ugfx.Button(160, 280, 100, 40, "Try again >", parent=None, shape=ugfx.Button.RECT, style=None)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def top_left_logo():
|
||||||
|
ugfx.clear(ugfx.html_color(0x000000))
|
||||||
|
try:
|
||||||
|
logo = http.get("https://i.imgur.com/5HXmXBU.png").raise_for_status().content
|
||||||
|
ugfx.display_image(0, 5, bytearray(logo))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def quit_loop():
|
||||||
|
while True:
|
||||||
|
if buttons.is_triggered(Buttons.BTN_Menu):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
profile = get_profile()
|
||||||
|
|
||||||
|
if profile is None:
|
||||||
|
render_splash_screen()
|
||||||
|
if not run_splash_screen():
|
||||||
|
break
|
||||||
|
profile = {
|
||||||
|
'username': "",
|
||||||
|
'age': "",
|
||||||
|
'tag_line': "",
|
||||||
|
'looking_for': "",
|
||||||
|
'contact': ""
|
||||||
|
}
|
||||||
|
if not create_profile(profile):
|
||||||
|
continue
|
||||||
|
|
||||||
|
main_screen(profile)
|
||||||
|
if not quit_loop():
|
||||||
|
break
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
import http, ugfx, buttons
|
||||||
|
from tilda import Buttons
|
||||||
|
from tildr.shared import top_left_logo
|
||||||
|
|
||||||
|
|
||||||
|
def get_next_person(state):
|
||||||
|
try:
|
||||||
|
resp = http.get(state['api']+'/get_user/'+state['profile']['unique_identifier']).json()
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if not resp['success']:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return resp['value']
|
||||||
|
|
||||||
|
|
||||||
|
def screen(state):
|
||||||
|
loading = ugfx.Container(0, 0, 240, 320)
|
||||||
|
loading.text(5, 100, "Loading...", ugfx.WHITE)
|
||||||
|
state['ui'].append(loading)
|
||||||
|
|
||||||
|
loading.show()
|
||||||
|
person = get_next_person(state)
|
||||||
|
loading.hide()
|
||||||
|
|
||||||
|
if person is None:
|
||||||
|
state['next'] = "NO_MORE"
|
||||||
|
return
|
||||||
|
|
||||||
|
window = ugfx.Container(0, 0, 240, 320)
|
||||||
|
window.show()
|
||||||
|
|
||||||
|
top_left_logo()
|
||||||
|
|
||||||
|
ugfx.set_default_font(ugfx.FONT_TITLE)
|
||||||
|
l1 = ugfx.Label(5, 90, 230, 40, person["username"], parent=window, justification=ugfx.Label.LEFTTOP)
|
||||||
|
ugfx.set_default_font(ugfx.FONT_SMALL)
|
||||||
|
window.text(200, 92, person["age"], ugfx.WHITE)
|
||||||
|
|
||||||
|
l2 = ugfx.Label(5, 120, 230, 60, person["tag_line"], parent=window)
|
||||||
|
|
||||||
|
l3 = ugfx.Label(5, 200, 230, 40, person["looking_for"], parent=window)
|
||||||
|
window.text(5, 180, "Looking for...", ugfx.RED)
|
||||||
|
|
||||||
|
if not person["contact"].startswith("@"):
|
||||||
|
person["contact"] = "@" + person["contact"]
|
||||||
|
|
||||||
|
window.text(5, 245, person["contact"], ugfx.BLUE)
|
||||||
|
|
||||||
|
b2 = ugfx.Button(0, 280, 120, 40, "< Edit profile", parent=window, shape=ugfx.Button.RECT, style=None)
|
||||||
|
b1 = ugfx.Button(120, 280, 120, 40, "Swipe >", parent=window, shape=ugfx.Button.RECT, style=None)
|
||||||
|
|
||||||
|
state['ui'].append(window)
|
||||||
|
state['ui'].append(l1)
|
||||||
|
state['ui'].append(l2)
|
||||||
|
state['ui'].append(l3)
|
||||||
|
state['ui'].append(b1)
|
||||||
|
state['ui'].append(b2)
|
||||||
|
|
||||||
|
|
||||||
|
def actions(state):
|
||||||
|
if buttons.is_triggered(Buttons.BTN_B) or buttons.is_triggered(Buttons.JOY_Right):
|
||||||
|
state['next'] = "NEXT_PERSON"
|
||||||
|
if buttons.is_triggered(Buttons.BTN_A) or buttons.is_triggered(Buttons.JOY_Left):
|
||||||
|
state['next'] = "PROFILE"
|
|
@ -0,0 +1,66 @@
|
||||||
|
import database, ujson, sim800, dialogs, http
|
||||||
|
|
||||||
|
|
||||||
|
def get_profile():
|
||||||
|
profile_json = database.get("tildr_profile")
|
||||||
|
if profile_json is None:
|
||||||
|
return {}
|
||||||
|
|
||||||
|
profile = ujson.loads(profile_json)
|
||||||
|
return profile
|
||||||
|
|
||||||
|
def create_profile(state):
|
||||||
|
try:
|
||||||
|
http.post(state['api']+'/create_user', json=state['profile']).raise_for_status().close()
|
||||||
|
except Exception as ex:
|
||||||
|
print(ex)
|
||||||
|
return False
|
||||||
|
|
||||||
|
profile_json = ujson.dumps(state['profile'])
|
||||||
|
database.set("tildr_profile", profile_json)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def screen(state):
|
||||||
|
|
||||||
|
if state['profile'] is None:
|
||||||
|
state['profile'] = {
|
||||||
|
'unique_identifier': "",
|
||||||
|
'username': "",
|
||||||
|
'age': "",
|
||||||
|
'tag_line': "",
|
||||||
|
'looking_for': "",
|
||||||
|
'contact': ""
|
||||||
|
}
|
||||||
|
|
||||||
|
ds = [
|
||||||
|
["username", "What's your name?"],
|
||||||
|
["age", "What's your age?"],
|
||||||
|
["tag_line", "Tell us your tagline"],
|
||||||
|
["looking_for", "And what you're looking for"],
|
||||||
|
["contact", "And your twitter username"],
|
||||||
|
]
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
|
||||||
|
while i < len(ds):
|
||||||
|
res = dialogs.prompt_text(ds[i][1], init_text=state['profile'][ds[i][0]])
|
||||||
|
if res is None:
|
||||||
|
i -= 1
|
||||||
|
if i < 0:
|
||||||
|
state['next'] = "SPLASH"
|
||||||
|
return
|
||||||
|
elif res != "":
|
||||||
|
state['profile'][ds[i][0]] = res
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
state['profile']['unique_identifier'] = sim800.imei()
|
||||||
|
|
||||||
|
if not create_profile(state):
|
||||||
|
state['next'] = "ERROR"
|
||||||
|
return
|
||||||
|
|
||||||
|
state['next'] = "NEXT_PERSON"
|
||||||
|
|
||||||
|
def actions(state):
|
||||||
|
return
|
|
@ -0,0 +1,12 @@
|
||||||
|
import ugfx, http
|
||||||
|
|
||||||
|
def clear():
|
||||||
|
ugfx.clear(ugfx.html_color(0x000000))
|
||||||
|
|
||||||
|
|
||||||
|
def top_left_logo():
|
||||||
|
try:
|
||||||
|
# logo = http.get("https://i.imgur.com/5HXmXBU.png").raise_for_status().content
|
||||||
|
ugfx.display_image(1, 5, "tildr/smalllogo.png")
|
||||||
|
except:
|
||||||
|
pass
|
Binary file not shown.
After Width: | Height: | Size: 910 B |
|
@ -0,0 +1,31 @@
|
||||||
|
import http, ugfx, buttons
|
||||||
|
from tilda import Buttons
|
||||||
|
from tildr.shared import clear
|
||||||
|
|
||||||
|
|
||||||
|
def screen(state):
|
||||||
|
window = ugfx.Container(0, 0, 240, 320)
|
||||||
|
window.show()
|
||||||
|
|
||||||
|
try:
|
||||||
|
# logo = http.get("https://i.imgur.com/0TjxEPs.png").raise_for_status().content
|
||||||
|
ugfx.display_image(
|
||||||
|
int((ugfx.width() - 164)/2),
|
||||||
|
20,
|
||||||
|
"tildr/biglogo.png")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
window.text(160, 100, "TILDR", ugfx.WHITE)
|
||||||
|
window.text(0, 270, "Find your match @emfcamp ;)", ugfx.WHITE)
|
||||||
|
window.text(45, 300, "Press A to begin", ugfx.WHITE)
|
||||||
|
|
||||||
|
state['ui'].append(window)
|
||||||
|
|
||||||
|
|
||||||
|
def actions(state):
|
||||||
|
if buttons.is_triggered(Buttons.BTN_A):
|
||||||
|
if state['profile'] is None:
|
||||||
|
state['next'] = "PROFILE"
|
||||||
|
else:
|
||||||
|
state['next'] = "NEXT_PERSON"
|
Loading…
Reference in New Issue