Skip to content

Commit

Permalink
upgrade to 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gxtrobot committed Sep 5, 2019
1 parent bcd6f2a commit c969fcb
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 34 deletions.
2 changes: 1 addition & 1 deletion bustag/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""bustag - a tag and recommend system for old bus driver"""

__version__ = '0.1.0'
__version__ = '0.1.1'
__author__ = 'gxtrobot <gxtrobot@gmail.com>'
__all__ = []
30 changes: 18 additions & 12 deletions bustag/app/index.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
from bottle import route, run, template, static_file, request, response, redirect
import bottle
import os
import sys
import threading
from collections import defaultdict
from bustag.app.schedule import start_scheduler
from bustag.util import logger
import threading
import sys
import os
import bottle
from multiprocessing import freeze_support
from bottle import route, run, template, static_file, request, response, redirect
from bustag.spider.db import get_items, RATE_TYPE, RATE_VALUE, ItemRate, Item
import bustag.model.classifier as clf
from bustag.util import logger, get_cwd
from bustag.app.schedule import start_scheduler

dirname = os.path.dirname(os.path.realpath(__file__))
bottle.TEMPLATE_PATH.insert(0, dirname+'/views/')
if getattr(sys, 'frozen', False):
dirname = sys._MEIPASS
print('dirname:' + dirname)
bottle.TEMPLATE_PATH.insert(0, dirname + '/views/')


@route('/static/<filepath:path>')
Expand Down Expand Up @@ -111,11 +115,13 @@ def do_training():


def start_app():
t = threading.Thread(target=start_scheduler, daemon=True)
t = threading.Thread(target=start_scheduler)
t.start()
# run(host='0.0.0.0', server='paste', port=8000, debug=True, reloader=True)
run(host='0.0.0.0', port=8000, debug=True)
run(host='0.0.0.0', server='paste', port=8000, debug=True)
# run(host='0.0.0.0', port=8000, debug=True)


if __name__ == "__main__":
freeze_support()
import bustag.model.classifier as clf
start_app()
13 changes: 8 additions & 5 deletions bustag/app/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from datetime import datetime, timedelta
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from apscheduler.triggers.interval import IntervalTrigger
from apscheduler.triggers.date import DateTrigger
from aspider import aspider
from bustag.spider import bus_spider
from bustag.util import logger, APP_CONFIG
import bustag.model.classifier as clf


def download(loop):
Expand All @@ -19,20 +19,23 @@ def download(loop):
bus_spider.reset_download()
aspider.main(loop)
try:
import bustag.model.classifier as clf

clf.recommend()
except FileNotFoundError:
print('还没有训练好的模型, 无法推荐')


def start_scheduler():
interval = int(APP_CONFIG['download.interval']) or 1800
interval = int(APP_CONFIG.get('download.interval', 1800))
loop = asyncio.new_event_loop()
scheduler = AsyncIOScheduler(event_loop=loop)
trigger = IntervalTrigger(seconds=interval)
t1 = datetime.now() + timedelta(seconds=10)
int_trigger = IntervalTrigger(seconds=interval)
date_trigger = DateTrigger(run_date=t1)
# add for down at server start
scheduler.add_job(download, 'date', run_date=t1, args=(loop,))
scheduler.add_job(download, trigger=trigger, args=(loop,))
scheduler.add_job(download, trigger=date_trigger, args=(loop,))
scheduler.add_job(download, trigger=int_trigger, args=(loop,))
scheduler.start()
asyncio.set_event_loop(loop)
loop.run_forever()
5 changes: 4 additions & 1 deletion bustag/app/views/base.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@
</div>

{{!base}}

<% from bustag import __version__ %>
<footer class="my-3">
<div class="container">
<div class="col">
<p class="text-center">
<span class="badge badge-pill badge-info">version : {{__version__}}</span>
</p>
<p class="text-center">
Developed by 凤凰山@2019 <a href="https://github.com/gxtrobot/bustag" target="_blank">github</a>
</p>
Expand Down
8 changes: 4 additions & 4 deletions bustag/app/views/tagit.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
%for item in items:
<form action="/tag/{{item.id}}?page={{curr_page}}&like={{like}}" method="post">
<div class="row py-3">
<div class="col-12 col-md-3">
<img src={{item.cover_img_url}} width="200">
<div class="col-12 col-md-4">
<img class="img-fluid img-thumbnail" src={{item.cover_img_url}}>
</div>

<div class="col-6 col-md-5">
<div class="col-7 col-md-5">
<div class="small text-muted">id: {{item.id}}</div>
<div class="small text-muted">发行日期: {{item.release_date}}</div>
<div class="small text-muted">添加日期: {{item.add_date}}</div>
Expand All @@ -42,7 +42,7 @@
</div>

</div>
<div class="col-6 col-md-4 align-self-center">
<div class="col-5 col-md-3 align-self-center">
<button type="submit" name="submit" class="btn btn-primary btn-sm" value="1">喜欢</button>
<button type="submit" name="submit" class="btn btn-danger btn-sm" value="0">不喜欢</button>
</div>
Expand Down
14 changes: 12 additions & 2 deletions bustag/util.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import logging
import os
import sys
import configparser
import pytz

logger = logging.getLogger('bustag')

DATA_PATH = './data/'
DATA_PATH = 'data/'
CONFIG_FILE = 'config.ini'
MODEL_PATH = 'model/'
APP_CONFIG = {}


def get_cwd():
if getattr(sys, 'frozen', False):
return sys._MEIPASS
else:
return os.getcwd()


def setup_logging():
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)


def get_data_path(file):
file_path = os.path.join(DATA_PATH, file)
cwd = get_cwd()
file_path = os.path.join(cwd, DATA_PATH, file)
return file_path


Expand Down Expand Up @@ -53,6 +62,7 @@ def check_model_folder():


def init():
print(f'CWD: {get_cwd()}')
setup_logging()
load_config()
check_model_folder()
Expand Down
1 change: 1 addition & 0 deletions data/config.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[download]
root_path = https://www.cdnbus.bid
count = 300
interval = 1800
19 changes: 12 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
aiohttp==3.5.4
alabaster==0.7.12
altgraph==0.16.1
appdirs==1.4.3
appnope==0.1.0
aspider
APScheduler==3.6.1
aspider==0.0.2
astroid==2.2.5
async-timeout==3.0.1
atomicwrites==1.3.0
Expand All @@ -17,47 +19,49 @@ bs4==0.0.1
category-encoders==2.0.0
certifi==2019.6.16
chardet==3.0.4
Click==7.0
coverage==4.5.4
cssselect==1.0.3
decorator==4.4.0
defusedxml==0.6.0
docopt==0.6.2
docutils==0.15.2
entrypoints==0.3
fake-useragent==0.1.11
gitdb==0.6.4
GitPython==0.3.6
gunicorn==19.9.0
idna==2.8
imagesize==1.1.0
importlib-metadata==0.19
ipykernel==5.1.1
ipython==7.7.0
ipython-genutils==0.2.0
ipywidgets==7.5.1
isort==4.3.21
jedi==0.14.1
Jinja2==2.10.1
joblib==0.13.2
jsonschema==3.0.2
jupyter==1.0.0
jupyter-client==5.3.1
jupyter-console==6.0.0
jupyter-core==4.5.0
lazy-object-proxy==1.4.1
lxml==4.4.0
macholib==1.11
MarkupSafe==1.1.1
mccabe==0.6.1
mistune==0.8.4
more-itertools==7.2.0
multidict==4.5.2
nbconvert==5.5.0
nbformat==4.4.0
notebook==6.0.0
numpy==1.17.0
numpy==1.17.1
packaging==19.1
pandas==0.25.0
pandocfilters==1.4.2
parse==1.12.0
parso==0.5.1
Paste==3.1.1
patsy==0.5.1
peewee==3.9.6
pexpect==4.7.0
Expand All @@ -70,6 +74,7 @@ py==1.8.0
pycodestyle==2.5.0
pyee==6.0.0
Pygments==2.4.2
PyInstaller==3.5
pylint==2.3.1
pyparsing==2.4.2
pypi-publisher==0.0.4
Expand Down Expand Up @@ -106,14 +111,14 @@ tornado==6.0.3
tqdm==4.32.2
traitlets==4.3.2
typed-ast==1.4.0
tzlocal==2.0.0
urllib3==1.25.3
w3lib==1.20.0
wcwidth==0.1.7
webencodings==0.5.1
websockets==8.0.2
widgetsnbextension==3.5.1
wrapt==1.11.2
yarg==0.1.9
yarl==1.3.0
zipp==0.5.2
click==7.0
gunicorn==19.9.0
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from setuptools import find_packages
from setuptools import setup
from bustag import __version__


def read(filename):
Expand All @@ -15,8 +16,8 @@ def read(filename):

setup(
name="bustag",
version="0.1.0",
url="https://github.com/borntyping/cookiecutter-pypackage-minimal",
version=__version__,
url="https://github.com/gxtrobot/bustag",
license='MIT',

author="gxtrobot",
Expand Down

0 comments on commit c969fcb

Please sign in to comment.