#!/usr/bin/env python3 # -*- coding:utf-8 -*- from lib.bottle import Bottle from lib.bottle import TEMPLATE_PATH from lib.bottle import jinja2_template from lib.bottle import request from sample.models.data import website app = Bottle() TEMPLATE_PATH.append('../sample/views') @app.route('/', method=["GET", "POST"]) def index(): add_website_page = "add_website.html" login_page = "login.html" session = request.environ.get('beaker.session') user_id = session.get("user_id", "") # セッション情報が残っていた場合 if user_id: cls_website = website.Website() attention = u"" website_name = request.forms.decode().get('website_name', "") website_link = request.forms.decode().get('website_link', "") website_keywords = request.forms.decode().get('website_keywords', "") complete_add_website = request.forms.get('complete_add_website', "False") if website_link: if not website_name: website_name = cls_website.get_website_title_with_link(website_link)
__author__ = 'reason' from lib.bottle import Bottle,TEMPLATE_PATH import index,shunion,option ,datareport ,nokiareport,ssx,wlapi,tdwap import setting TEMPLATE_PATH.insert(0,setting.TEM_PATH) app=Bottle() app.mount("/nokiadata",nokiareport.app) app.mount("/data",datareport.app) app.mount("/index",index.app) app.mount("/shunion",shunion.app) app.mount("/option",option.app) app.mount("/ssx",ssx.app) app.mount("/wlapi",wlapi.app) app.mount("/tdwap",tdwap.app)
days_in_advance = 3 events = {} now = datetime.datetime.utcnow() for d in range(days_in_advance): tm = now + datetime.timedelta(days=d) events[tm.strftime("%A")] = get_event_for_day(tm.date()) return events def get_news(): d = feedparser.parse(NEWS_FEED) return d['entries'] tpl_path = os.path.join(get_script_rel_path("templates")) TEMPLATE_PATH.insert(0, tpl_path) if __name__ == '__main__': parser = argparse.ArgumentParser(description='starts a lists server') parser.add_argument( '--config', help='specifies the config file location (default: ./config.json)', default="./config.json") args = parser.parse_args() with open(args.config) as f: config = json.load(f) run(host='0.0.0.0', port=config['port'], reloader=True) app = default_app()
# Connect to the database. conn = sqlite3.connect(config["paths"]["file_auth_database"]) c = conn.cursor() # Save new user in the database. c.execute("INSERT INTO `secure_login`(`ID`,`Username`,`Password`) VALUES (?,?,?)", (None, new_username, hash)) conn.commit() c.close() # Redirect. response.status = 303 response.set_header('Location', '/users') else: # Redirect. response.status = 303 response.set_header('Location', '/users') """ # Part 4: Send to daemon - No the above code will be launched in the daemon script located in the /lib directory. """ # This is a fix for the view directory. TEMPLATE_PATH.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "view"))) # Pass this code to the lib.bottledaemon so the server can start. from lib.bottledaemon import daemon_run if __name__ == "__main__": daemon_run()
#!bin/python3 # coding=utf8 from lib.bottle import run, view, template, request, response, route, post, get, static_file, TEMPLATE_PATH, debug from lib import mylib, config from poster import Poster ################################################# debug(True) TEMPLATE_PATH.append('./template') exception_format = ' <span style="color: red">%s :(</span>' config = config.Config('config.cfg') # 格式: posters = {username: Poster} #test_poster = Poster( #{'username': '******', 'password': '******'}, #config.get_section('global')['global'], #config.get_section('user_section1')['user_section1'] #) #posters = {'test': test_poster} posters = {} auths = {} is_action = False ################################################# def get_form_dict(form, is_user_section=False): """ is_user_seciton 参数, 是为了处理 checkbox 和 radiobox 不选中时不传值过来的情况 """ temp = {} if is_user_section: temp = { 'is_random': '0', 'is_repeat': '0' } for key in form: