def check_upvote_l(memeid): upvote_data = Upvote.get_upvotes_for_memes(memeid) return str(len(upvote_data)) def post_handler(response, i): dp = 'http://i0.kym-cdn.com/profiles/icons/big/000/132/880/awesome%20face%20shrug.jpg' rendered = render_file("pages/post.html", { "dp": dp, "meme": Meme.get_meme_from_id(i) }) response.write(rendered) server = Server() server.register('/', index_handler) server.register('/feed', feed_handler) server.register('/upload', upload_handler) server.register('/login', login_handler) server.register('/logout', logout_handler) server.register('/signup', signup_handler) server.register(r'/post/(.+)', post_handler) #--------------- server.register(r'/profile/(.+)', profile_handler) server.register('/index_example', index_example) server.register('/nearby', nearby_handler) server.register(r'/upvote_meme/(.+)', upvote_meme) server.register(r'/check_upvote/(.+)', check_upvote)
return "blue" elif red_win: return "red" ######################################################################### ### General Database checking functions for everywhere ### def player_in_game(response, roomcode): player_id = get_player_id_cookies(response) in_game = db.player_in_game(player_id, roomcode) return in_game server = Server() #server.register("/", index, post=add_name_page) server.register("/", index_page) server.register("/register", register_user_post) server.register("/login", login_post) server.register("/join_game", join_game_page) server.register("/game/create", create_game_post) server.register("/game/join", join_game_post) server.register("/lobby/([a-z]+)", lobby_page) server.register("/game/([a-z]+)", game_page) server.register("/game/startgame/([a-z]+)", start_game_post) server.register("/game/([a-z]+)", game_page) db.init() server.run()
def help(response): current_user = get_logged_in(response) page_html = template.template.render("help.html", {'current_user':current_user}) response.write(page_html) def forgot_password_page(response): current_user = get_logged_in(response) page_html = template.template.render("forgot.html", {'show_chat': False, 'current_user':current_user}) response.write(page_html) def canvas(response): current_user = get_logged_in(response) page_html = template.template.render("canvas.html", {'show_chat': True, 'current_user':current_user}) response.write(page_html) server = Server(port = 8888) server.register("/", index) server.register("/signup/?", signup) server.register("/logout/?", logout) server.register("/login/?", login) server.register("/user/([A-Za-z0-9\._]+)/edit/?", edit_user) server.register("/user/([A-Za-z0-9\._]+)/change_password", change_password) server.register("/help/?", helpme) server.register("/gallery/?", gallery) server.register("/image/?", image_upload) server.register("/user/?", redirect_user) server.register("/forgot/?", forgot_password_page) server.register("/user/([A-Za-z0-9\._]+/?)", user) server.register("/about/?", about) server.register("/canvas/?", canvas) server.register("/image/([0-9]+/?)", image)
def init_server(**kwargs): server = Server(**kwargs) # API pages server.register('/game', game) server.register('/player', player, post=player) server.register('/murder', murder, post=murder_submit) server.register('/achievement_progress', achievement_progress) server.register('/login', login_page, post=login) # HTML pages game_id = '/([0-9a-zA-Z-]+)' player_id = '([a-zA-Z+-]+)' server.register('/admin/?', admin) server.register('{}/admin/?'.format(game_id), admin) server.register('{}/admin/lodge/?'.format(game_id), lodge) server.register('{}/profiles/?'.format(game_id), profiles) server.register('{}/profiles/{}/?'.format(game_id, player_id), profile) server.register('{}/map/?'.format(game_id), murder_map) server.register('{}/murders/?'.format(game_id), murder_list) server.register('{}/stats/?'.format(game_id), stats) server.register('{}/achievements/?'.format(game_id), achievements) server.register('{}?/?'.format(game_id), home) return server
context )) def scoreboard(response): variables = { 'users': user.User.user_list(), 'user': get_current_user(response) } response.write(render( 'templates/scoreboard.html', variables )) if __name__ == "__main__": server = Server() server.register("/", stories) server.register("/style.css", style) server.register("/story", create) server.register("/story/(\d+)", view_story) server.register("/story/(\d+)/word/(\d+)/vote", upvote) server.register("/story/(\d+)/(\d+)/reply", add_word) server.register('/login', login) server.register('/logout', logout) server.register('/register', register) server.register('/mystories', my_stories) server.register('/scoreboard', scoreboard) server.register('/user/(\w+)', profile) server.run()
def run_server(srvhost='', serverport=8888): server = Server(write_error=handle_error, hostname=srvhost, port=serverport) server.register('/users/([a-zA-Z0-9_]+)', profile) server.register('/users/([a-zA-Z0-9_]+)/item', add_item) server.register('/users/([a-zA-Z0-9_]+)/item/([a-zA-Z0-9_]+)', get_item, delete=delete_item) server.register('/users/([a-zA-Z0-9_]+)/edit_item/([a-zA-Z0-9_]+)', edit_item) server.register('/users/([a-zA-Z0-9_]+)/edit', edit_user) server.register('/friends', friends_list) server.register('/add_friend/([a-zA-Z0-9_]+)', add_friend) server.register('/delete_friend/([a-zA-Z0-9_]+)', delete_friend) server.register('/login', login) server.register('/logout', logout) server.register('/signup', signup) server.register('/ajax/scrape', scrape.scrape_url) server.register('/', home) server.register('/mywishlist', my_wishlist) server.register('/feed', feed) server.register('/search', search) server.register('.*', handle_error) server.run()
render_page("create_location.html", response, context) return name = response.get_field("name") if orig_name != name: if Location.find_name(name): context["error"] = "Place already exists" render_page("edit_location.html", response, context) return None description = response.get_field("description") address = response.get_field("address") Location.change_location(id, name, description, location.picture, address, lat, lon) response.redirect("/location/" + id) if __name__ == "__main__": server = Server(hostname="0.0.0.0", port=8888) server.register(r"/", index_handler) server.register(r"/account/signup", signup_handler, post=signup_authentication) server.register(r"/account/login", login_handler, post=login_authentication) server.register(r"/location/search", search_handler) server.register(r"/location/(\d+)", location_handler, post=rating) server.register(r"/location/(\d+)/comment", comment_handler, post=comment_post) server.register(r"/location/create", create_handler, post=location_creator) server.register(r"/location/edit/(\d+)", edit_handler, post=location_editor) server.register(r"/account/profile/([a-z0-9A-Z._]+)", profile_handler) server.register(r"/account/profile", profile_handler) server.register(r"/account/logout", logout_handler) server.register(r".*", error_handler) server.run()
def logout_handler(request): if not is_authorised(request): request.redirect(r'/') return request.clear_cookie('user_id') request.redirect(r'/') def error404_handler(request): request.write(render_template('error404.html', {'title' : "Error 404" })) # GET /list/create - Call create screen # POST /list/create - Post list to server and redirects to created list. # GET /list/<listID> - Shows list referring to listID or says list not found. # GET / - If not logged in, Shows decription and if you are, shows feed. server = Server(hostname = '0.0.0.0') server.register(r'/', index_handler) server.register(r'/login', login_handler) server.register(r'/list/(\d+)/create', list_creation_handler) server.register(r'/list/(\d+)', list_display_handler) server.register(r'/list/(\d+)/edit', list_edit_handler) server.register(r'/logout', logout_handler) server.register(r'/user/create', signup_handler) server.register(r'/user/edit', profile_edit_handler) server.register(r'/timeline/([0-9]+)', timeline_handler) server.register(r'/.+', error404_handler) server.run()
app_log.info("[%s found for '%s'] %s" % (response.get_field('t'), search, items)) response.write(epyc.render("templates/search.html", scope)) else: scope = { "query": "", "results": [], "tp": tp, "types": types, "logged_in": get_current_user(response) } response.write(epyc.render("templates/search.html", scope)) def hello(response, match): response.write(epyc._render(''' <html> <header>:)</header> <body> <h1>Hellos peoples of the internets</h1> </body> </html> ''')) if __name__ == '__main__': server=Server() server.register('/search',search) server.register('/friends/([a-zA-Z0-9_]+)', friends_list) server.run()
profile_id = response.get_field('profile_id') render_wall(response, profile_id) def post(response): user = get_user(response) if user is None: return profile_id = response.get_field('profile_id') wall = User.get(id=profile_id) msg = response.get_field('msg') user.add_post(wall, msg) render_wall(response, wall.id) def search(response): pass if __name__ == '__main__': server = Server() server.register('/', index) server.register('/logout', logout) server.register('/profile', profile) server.register('/profile/([0-9]+)$', profile) server.register('/wall', wall) server.register('/post', post) server.register('/search', search) server.run()
pictureFile.write(image[2]) createPost = Post.create(user.user_id, title, description, pictureName, location) response.redirect("/post/" + str(createPost.id)) @loginRequired def comment_post(response, post_id): user = get_current_user(response) comment = response.get_field("comment") if comment: comment = Comment.create(user.user_id, post_id, comment) response.redirect('/post/' + post_id) database_connect('db/street.db') server = Server() server.register(r'/?(?:home)?', home) server.register(r'/profile(?:(?:/([\w\.\-]+)?)|/?)', profile) server.register(r'/login', login, post=login_handler) server.register(r'/signup', signup, post=signup_handler) server.register(r'/post/(\d+)', view_post, post=comment_post) server.register(r'/submit', submit, post=submit_handler) server.register(r'/demo', demo) server.register(r'/logout', logout) server.register(r'.+', notfound) server.run()
import templater import db ''' TO DO LIST: - add list_id to the URL for registering view and edit - complete handler functions for: - feed_handler - dashboard_handler - create_handler - view_handler - edit_handler ''' db.connect_or_create() server = Server() # Handlers server.register(r'/', handlers.index_handler) server.register(r'/login', handlers.get_login_handler, get = handlers.get_login_handler, post = handlers.post_login_handler) server.register(r'/logout', handlers.logout_handler) server.register(r'/signup', handlers.index_handler, post = handlers.post_signup_handler) server.register(r'/feed', handlers.feed_handler) server.register(r'/dashboard', handlers.dashboard_handler) server.register(r'/create', handlers.create_handler, post = handlers.create_post_handler) server.register(r'/list/(\d+)/view', handlers.view_handler) server.register(r'/list/(\d+)/edit', handlers.edit_handler, post = handlers.edit_post_handler) server.register(r'/list/(\d+)/delete', handlers.delete_handler) server.register(r'/memes', handlers.meme_handler) server.register(r'/privacy', handlers.privacy_handler) server.register(r'/terms', handlers.terms_handler)
def deny_topic_handler(request, pendingtopicid): user_id = request.get_secure_cookie('user_id') if user_id: if int(user_id.decode("UTF-8")) == 1: remove_newpending_topic('./database/pending-topics.db', pendingtopicid) request.redirect('/approve/') else: render(request, "pagenotfound.html", {"login": check_logged_in(request)}) #Registers all of the url's going to be used. If one of these matches, it will call the handler attached and/or the POST method handler (for forms) # This uses regex to make matches. The (\+) section is where a variable id goes - this gets parsed to the handler as well. server = Server() # Create a server object server.register(r'/', index_handler) server.register(r'/search/', searchpage_handler) server.register(r'/searchresults/(.*)/', searchresult_handler) server.register(r'/user/(\d+)/', profile_handler) server.register(r'/user/deletecomment/(\d+)/', remove_comment_handler) server.register(r'/user/updateprofile/(\d+)/', update_profile_handler, post=update_profile_form) server.register(r'/topic/(\d+)/', topicpage_handler, post=comment_creator_handler) server.register(r'/topicl/(\d+)/', topicpagel_handler, post=comment_creator_handler) server.register(r'/login/', login_handler, post=post_login_handler)
'templates/userProfile.html', context )) def scoreboard(response): variables = { 'users': user.User.user_list(), 'user': get_current_user(response) } response.write(render( 'templates/scoreboard.html', variables )) if __name__ == '__main__': server = Server() server.register('/', stories) server.register('/story', create) server.register('/story/(\d+)', view_story) server.register('/story/(\d+)/word/(\d+)/vote(/remove)?', vote) server.register('/story/(\d+)/(\d+)/reply', add_word) server.register('/login', login) server.register('/logout', logout) server.register('/register', register) server.register('/mystories', my_stories) server.register('/scoreboard', scoreboard) server.register('/user/(\w+)', profile) server.run(debug=False)
def index_handler(request): request.write("hello there") param_name = request.get_field("name") if param_name != None: request.write("<br>") request.write(param_name) request.write("!") def book_handler(request, book_id): request.write(book_id) def test_reader(request): template = get_template('test.html') fname = request.get_field('fname') lname = request.get_field('lname') food = request.get_field('food') user = {'fname': fname, 'lname': lname, 'food': food} render_file(request, 'test.html', user) server = Server() server.register(r'/', index_handler) server.register(r'/book/(\d+)/?', book_handler) server.register(r'/test', test_reader) server.run()
'signed_in': authenticate_cookie(request), 'username': get_username(request) })) def not_found_handler(request): request.write( render( '404.html', { 'users': db.User.find_all(), 'signed_in': authenticate_cookie(request), 'username': get_username(request) })) server = Server() server.register(r'/', index_handler) server.register(r'/view/(\d+)/?', view.view_question_handler) server.register(r'/signup', user.signup_handler, post=user.signup_handler_post) server.register(r'/ask', ask.ask_handler, post=ask.ask_handler_post) server.register(r'/signin', user.signin_handler, post=user.signin_handler_post) server.register(r'/post_comment/(\d+)/?', view.comment_handler_post, post=view.comment_handler_post) server.register(r'/logout', user.signout_handler) server.register(r'/list_users', handle_list_users) server.register(r'/profile/(.+)', profile.view_handler, post=profile.view_handler_post) server.register(r'/profile/edit/(.+)', profile.edit_handler,
def init_server(**kwargs): server = Server(**kwargs) # API pages server.register('/game', game) server.register('/player', player, post=player) server.register('/murder', murder, post=murder_submit, delete=murder_delete) server.register('/achievement_progress', achievement_progress) server.register('/signup', signup_page, post=signup) server.register('/login', login_page, post=login) server.register('/disable', disable, post=disable) server.register('/simple_stats', simple_stats) # HTML pages game_id = '/([0-9a-zA-Z-]+)' player_id = '([\w\W+-]+)' player_code = '([0-9a-zA-Z]+)' server.register('/admin/?', admin) server.register("/k", log_kill_redirect) server.register("/k/{}?".format(player_code), log_kill_redirect) server.register('{}/admin/?'.format(game_id), admin) server.register('{}/admin/lodge/?'.format(game_id), lodge) server.register('{}/profiles/?'.format(game_id), profiles) server.register('{}/profiles/{}/?'.format(game_id, player_id), profile) server.register('{}/map/?'.format(game_id), murder_map) server.register('{}/murders/?'.format(game_id), murder_list) server.register('{}/stats/?'.format(game_id), stats) server.register('{}/achievements/?'.format(game_id), achievements) server.register('{}/achievements_stat/([0-9]+)'.format(game_id), achievements_stat) server.register('{}/kill/?(?:/{})?/?'.format(game_id, player_code), log_kill, post=log_kill) server.register('{}?/?'.format(game_id), home) return server
def init_server(): server = Server() # API pages server.register('/game', game) server.register('/player', player, post=player) server.register('/murder', murder, post=murder) # HTML pages game_id = '/([0-9a-zA-Z-]+)' player_id = '([a-zA-Z+-]+)' server.register('/admin/?', admin) server.register('{}/admin/?'.format(game_id), admin) server.register('{}/admin/lodge/?'.format(game_id), lodge) server.register('{}/profiles/?'.format(game_id), profiles) server.register('{}/profiles/{}/?'.format(game_id, player_id), profile) server.register('{}/murders/?'.format(game_id), murder_list) server.register('{}?/?'.format(game_id), home) return server
#!/usr/bin/env python3 import os from tornado.ncss import Server def index(response): response.write('Hello World!') port = os.getenv('PORT') if port: server = Server(port=int(port)) else: server = Server() server.register('/', index) server.run()
request.write(templater.render("templates/charity_list.html", context)) def default_handler(request, method): request.write("Invaild url silly!") """Redirects all invalid urls to this""" """def next_charity_handler(request, )""" """ Sends user to new page and sends info to data base""" # \d+ is any number # .+ = any letter but preferably a name!! args = parser.parse_args() server = Server(port=args.port) server.register(r"/?", home_page_handler) server.register(r"/charity_profile/(\d+)/?", charity_profile_handler) server.register(r"/create_charity_profile/?", create_charity_profile_handler) server.register(r"/post_create_charity_profile/?", post_create_charity_profile_handler) server.register(r"/swipe/(\d+)/(left|right)/?", swipe_screen_handler) server.register(r"/feed/?", feed_handler) server.register(r"/about/?", about_handler) server.register(r"/user_profile/(\d+)/(.+)/?", user_profile_handler) server.register(r"/create_user_profile/?", create_user_profile_handler) server.register(r"/post_create_user_profile/?", post_create_user_profile_handler) server.register(r"/user/?", user_handler) server.register(r"/charity_list/?", charity_list_handler) server.set_default_handler(default_handler)
</head> <body> <li><a href="/about"> About </a></li> </body> ''') def vote(response): user = response.get_field("user") # simply "user" as for now song = response.get_field("song") # Song ID vote = response.get_field("vote") # 1:UP,0:DOWN params = [user, song, vote] respDict = {"user": user, "song": song, "vote": vote} respDict["success"] = API.vote(params) response.write(respDict) def fourofourhandler(response): writeResponse(response, 'templates/404.html') server = Server() server.register('/', home) server.register('/profile', profile) server.register('/style-guide', style) server.register('/song-player', index) server.register('/about', about) server.register('/vote', vote) server.register('/songdb', songdb) server.register(r'/.+', fourofourhandler) server.run()
db.update_game_player(game_id, player_id, "red", "True") else: if i % 2 == 0: db.update_game_player(game_id, player_id, "blue", "False") else: db.update_game_player(game_id, player_id, "red", "False") ######################################################################### ### General Database checking functions for everywhere ### def player_in_game(response, roomcode): player_id = get_player_id_cookies(response) in_game = db.player_in_game(player_id, roomcode) return in_game server = Server() #server.register("/", index, post=add_name_page) server.register("/", index_page) server.register("/register", register_user_post) server.register("/login", login_post) server.register("/join_game", join_game_page) server.register("/game/create", create_game_post) server.register("/game/join", join_game_post) server.register("/lobby/([a-z]+)", lobby_page) server.register("/game/startgame/([a-z]+)", start_game_post) server.register("/game/([a-z]=)", game_page) db.init() server.run()
def reject_squad_member(request, name): """ >>> tornadotesting.run(reject_squad_member, 'ateam') 'This page reject ateam' """ request.write('This page reject {}'.format(name)) def apply_to_squad(request, name): """ >>> tornadotesting.run(apply_to_squad, 'ateam') 'This the page to apply to join ateam' """ request.write('This the page to apply to join {}'.format(name)) server = Server() server.register(r'/profiles/([a-z]+)/', view_profile) server.register(r'/register/', create_profile_page, post=create_profile) server.register(r'/squads/', list_squads, post=create_squad) server.register(r'/squads/([a-z]+)/', view_squad) server.register(r'/create-squad/', show_create_squad_page) server.register(r'/squads/([a-z]+)/accept/', accept_squad_member) server.register(r'/squads/([a-z]+)/reject/', reject_squad_member) server.register(r'/squads/([a-z]+)/apply/', apply_to_squad) if __name__ == '__main__': server.run()
if password != confpass: request.redirect('/profilecreation/') for f in profile_fields: field.append(request.get_field(f)) user = create_seeker('./database/seekers_personal.db', field) request.set_secure_cookie('user_id', str(user.id)) request.redirect('/') def pagenotfound_handler(request): render(request, 'pagenotfound.html', {"login": check_logged_in(request)}) server = Server() # Create a server object server.register(r'/', index_handler) try: from chatbot.ai import ChatBotWebSockets # def chat_handler (request): # return render(request, 'chatbot/chat.html', {"login": check_logged_in(request)}) server.register(r'/ws/', ChatBotWebSockets) # server.register(r'/chat/', chat_handler) except ImportError: pass server.register(r'/profile/', profilelistpage_handler) server.register(r'/searchresult/(.*)/(.+)/', searchresult_handler) server.register(r'/position/', positionlist_handler) server.register(
def input_handler(response): aih = ActivityInputHandler(activity_dict) response.write(render("input_activity.html", aih.get_template_data())) def updateprofile_handler(response): response.write(render("update_profile.html", {'a': 'B'})) def template_demo(response): response.write(render("test.html", {'a': 'B'})) def search_handler(response): response.write(render("search_results.html", {'a': 'B'})) def login_handler(response): response.write(render("login.html", {'a': 'B'})) server = Server() server.register(r"/", landing_handler) server.register(r"/home/", home_handler) server.register(r"/register/", register_handler) server.register(r"/profile/(\d+)/", profile_handler) server.register(r"/input/", input_handler) server.register(r"/updateprofile/", updateprofile_handler) server.register(r"/search/", search_handler) server.register(r"/template/", template_demo) server.register(r"/login/", login_handler) server.run()