From fdd22877615fd8b2b5674acee32a217383f676f7 Mon Sep 17 00:00:00 2001 From: Andrey Anokhin Date: Sat, 17 Aug 2019 13:04:58 +0300 Subject: [PATCH 01/22] Basic structure of flask-app --- app/__init__.py | 15 +++++++++++++++ app/forms.py | 1 + app/models.py | 4 ++++ app/routes.py | 9 +++++++++ app/templates/index.html | 1 + app/tests.py | 1 + config.py | 13 +++++++++++++ eriwan_podcast.py | 2 ++ 8 files changed, 46 insertions(+) create mode 100644 app/__init__.py create mode 100644 app/forms.py create mode 100644 app/models.py create mode 100644 app/routes.py create mode 100644 app/templates/index.html create mode 100644 app/tests.py create mode 100644 config.py create mode 100644 eriwan_podcast.py diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..2b7660c --- /dev/null +++ b/app/__init__.py @@ -0,0 +1,15 @@ +# Creates the application object as an instance of class Flask + + +from flask import Flask +from config import Config + +app = Flask(__name__) + +# using Config class from ./config.py +app.config.from_object(Config) + +# The routes module is imported at the bottom and not at the top of the script +# as it is always done. The bottom import is a workaround to circular imports, +# a common problem with Flask applications. +from app import routes, models diff --git a/app/forms.py b/app/forms.py new file mode 100644 index 0000000..8dd6df3 --- /dev/null +++ b/app/forms.py @@ -0,0 +1 @@ +# Here will be Flask Web Forms diff --git a/app/models.py b/app/models.py new file mode 100644 index 0000000..3cb39d5 --- /dev/null +++ b/app/models.py @@ -0,0 +1,4 @@ +# Here will be Classes with model definitions + +# from app import app, db +# Here will be db models diff --git a/app/routes.py b/app/routes.py new file mode 100644 index 0000000..4ee1448 --- /dev/null +++ b/app/routes.py @@ -0,0 +1,9 @@ +# View functions +from flask import render_template +from app import app + + +@app.route('/') +def index(): + feed_blank = 'Podcast Main page: RSS feed' + return render_template('index.html', feed_blank=feed_blank) diff --git a/app/templates/index.html b/app/templates/index.html new file mode 100644 index 0000000..7789fb0 --- /dev/null +++ b/app/templates/index.html @@ -0,0 +1 @@ +{{ feed_blank }} \ No newline at end of file diff --git a/app/tests.py b/app/tests.py new file mode 100644 index 0000000..74813ec --- /dev/null +++ b/app/tests.py @@ -0,0 +1 @@ +# Here will be tests diff --git a/config.py b/config.py new file mode 100644 index 0000000..183a890 --- /dev/null +++ b/config.py @@ -0,0 +1,13 @@ +# Config Classes + +import os +basedir = os.path.abspath(os.path.dirname(__file__)) + + +class Config(object): + SECRET_KEY = os.environ.get('SECRET_KEY') or 'you-will-never-guess' + SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \ + 'sqlite:///' + os.path.join(basedir, 'app.db') + SQLALCHEMY_TRACK_MODIFICATIONS = False + + ADMINS = ['your-email@example.com'] diff --git a/eriwan_podcast.py b/eriwan_podcast.py new file mode 100644 index 0000000..2741a3e --- /dev/null +++ b/eriwan_podcast.py @@ -0,0 +1,2 @@ +# The top-level that defines the Flask application instance +from app import app From ccf2e869c9cb52cd2ed6340870f71b0d8e41b2a7 Mon Sep 17 00:00:00 2001 From: Andrey Anokhin Date: Sat, 17 Aug 2019 13:09:59 +0300 Subject: [PATCH 02/22] Create requirements.txt and add flask to it. --- requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7e10602 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +flask From c23b4b24e9967c171e41e175f72e89f97a59c072 Mon Sep 17 00:00:00 2001 From: Andrey Anokhin Date: Sat, 17 Aug 2019 13:21:49 +0300 Subject: [PATCH 03/22] how to run --- HOW TO RUN FLASK APP.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 HOW TO RUN FLASK APP.md diff --git a/HOW TO RUN FLASK APP.md b/HOW TO RUN FLASK APP.md new file mode 100644 index 0000000..a425cfc --- /dev/null +++ b/HOW TO RUN FLASK APP.md @@ -0,0 +1,6 @@ +# HOW TO RUN FLASK APP +```sh +export FLASK_APP=eriwan_podcast.py +export FLASK_DEBUG=1 +flask run +``` From b0866e72aa72fa515bd69fce3262508ee327f56c Mon Sep 17 00:00:00 2001 From: Mo1far <38346000+Mo1far@users.noreply.github.com> Date: Sat, 17 Aug 2019 13:32:07 +0300 Subject: [PATCH 04/22] Update config.py changed SEKRET_KEY to a more complex version --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 183a890..25c57a4 100644 --- a/config.py +++ b/config.py @@ -5,7 +5,7 @@ class Config(object): - SECRET_KEY = os.environ.get('SECRET_KEY') or 'you-will-never-guess' + SECRET_KEY = os.environ.get('SECRET_KEY') or 'Wo7GhuD2OWIv' SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \ 'sqlite:///' + os.path.join(basedir, 'app.db') SQLALCHEMY_TRACK_MODIFICATIONS = False From 94533bb0abbc67e949da6066732e542156cc7c3b Mon Sep 17 00:00:00 2001 From: Alexander Shustrov Date: Sat, 17 Aug 2019 13:46:42 +0300 Subject: [PATCH 05/22] added idea settings into gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 6f667ed..7018eb4 100644 --- a/.gitignore +++ b/.gitignore @@ -105,3 +105,6 @@ venv.bak/ # direnv .envrc + +# ideas +.vscode From a6548857124d6b19e9557ec583dab95717f8e901 Mon Sep 17 00:00:00 2001 From: Aleksander Date: Sat, 17 Aug 2019 14:53:05 +0300 Subject: [PATCH 06/22] created models and database settings --- HOW TO RUN FLASK APP.md | 5 ++ app.db | Bin 0 -> 32768 bytes app/__init__.py | 8 +++ app/models.py | 73 +++++++++++++++++++- config.py | 2 + migrations/README | 1 + migrations/alembic.ini | 45 +++++++++++++ migrations/env.py | 96 +++++++++++++++++++++++++++ migrations/script.py.mako | 24 +++++++ migrations/versions/6301de4834d1_.py | 55 +++++++++++++++ requirements.txt | 7 +- 11 files changed, 312 insertions(+), 4 deletions(-) create mode 100644 app.db create mode 100644 migrations/README create mode 100644 migrations/alembic.ini create mode 100644 migrations/env.py create mode 100644 migrations/script.py.mako create mode 100644 migrations/versions/6301de4834d1_.py diff --git a/HOW TO RUN FLASK APP.md b/HOW TO RUN FLASK APP.md index a425cfc..6e0ea33 100644 --- a/HOW TO RUN FLASK APP.md +++ b/HOW TO RUN FLASK APP.md @@ -2,5 +2,10 @@ ```sh export FLASK_APP=eriwan_podcast.py export FLASK_DEBUG=1 + +flask db init +flask db migrate +flask db upgrade + flask run ``` diff --git a/app.db b/app.db new file mode 100644 index 0000000000000000000000000000000000000000..db697ed4f2b3d83d7c9e044580c6a55bc2e31f25 GIT binary patch literal 32768 zcmeI&OHUI)0KoBG9xbhwdTDy#G8bYuAn5}LAu(F&0u5y=OHnv&7P^L&KCllZ@dSP# z&wc>Ek4I0&nWcqpqulh+{5PHMygT!oX_LwJ@Sx)NJn^pGX}Ud8(4J_zuDujO)3m4z zb21FCh>Xk(6Y{Q)#QzqJYAe~zMDnK=ee_F9CX(OgQ;F}1#^bLt$%Oy{2q1s}0tg_0 z00RG2;Cdw*O{Y@&&5NFU+VI}DFM=>vvdv=66t&`3#S|)6Wa2TuF3MKT+%auoRcpdJ zs#KOmJf@1Bo_Ey~HS<_zj}-O0UdOp_rfR>o%lk$9MC_R-BIDN$mA75B&GL?=@-l-a zhOo_T(>AS=c_>s~P&sZ~Z$_f&g$4a)FBq_Q>37?8Z*Yr-hCRr9VB{^g>4`T*yR=)h zGx@bO;~x+H?QA6dETw<;TXpZszjA`Psy8(db&m`taAcJaj!dcj$~+e16-Ct=hzy$= z)=VV*G^Mvg9eYjJZ>TD>5A_<PRJ9Ikc2Rz>#8?l`<;9r@O<<%yIo9V>k@Ufmt_5q}{m_u7c*pJcZufvQ-dS!e zV_N>q1ZVq%jOfW9ntX8~fB*srAbr;#Cg>0_wt!@-n>$$j` z7w7*8SzM-p00IagfB*srAb' + + def set_password(self, password): + self.password_hash = generate_password_hash(password) + + def check_password(self, password): + return check_password_hash(self.password_hash, password) + + +class Episode(db.Model): + id = db.Column(db.Integer, primary_key=True) + name = db.Column(db.String(255), nullable=False) + user_id = db.Column(db.Integer, db.ForeignKey('user.id')) + + def __repr__(self): + return f', name: {self.name}' + + def get_file_path(self): + ''' + Return wrapped in jingles file path + ''' + static_path = os.path.join(app.config.STATIC_ROOT, 'episodes') + file_path = f'{static_path}/{self.id}.mp3' + if os.path.exists(file_path): + return file_path + + # todo: add to celery task + def generate_wrapped_file(self, upload_file): + ''' + Generate file with name of episode prefix from upload_file + ''' + pass + + +class Joke(db.Model): + id = db.Column(db.Integer, primary_key=True) + joke_text = db.Column(db.Text, nullable=False) + user_id = db.Column(db.Integer, db.ForeignKey('user.id')) + + def __repr__(self): + return f', name: {self.name}' + + def get_file_path(self): + ''' + Return wrapped in jingles file path + ''' + static_path = os.path.join(app.config.get('STATIC_ROOT'), 'jokes') + file_path = f'{static_path}/{self.id}.mp3' + if os.path.exists(file_path): + return file_path + + # todo: add to celery task + def generate_wrapped_file(self, upload_file): + ''' + Generate wrapped in jingles file from upload_file + ''' + pass diff --git a/config.py b/config.py index 25c57a4..94849ca 100644 --- a/config.py +++ b/config.py @@ -11,3 +11,5 @@ class Config(object): SQLALCHEMY_TRACK_MODIFICATIONS = False ADMINS = ['your-email@example.com'] + + STATIC_ROOT = '/static/' diff --git a/migrations/README b/migrations/README new file mode 100644 index 0000000..98e4f9c --- /dev/null +++ b/migrations/README @@ -0,0 +1 @@ +Generic single-database configuration. \ No newline at end of file diff --git a/migrations/alembic.ini b/migrations/alembic.ini new file mode 100644 index 0000000..f8ed480 --- /dev/null +++ b/migrations/alembic.ini @@ -0,0 +1,45 @@ +# A generic, single database configuration. + +[alembic] +# template used to generate migration files +# file_template = %%(rev)s_%%(slug)s + +# set to 'true' to run the environment during +# the 'revision' command, regardless of autogenerate +# revision_environment = false + + +# Logging configuration +[loggers] +keys = root,sqlalchemy,alembic + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = WARN +handlers = console +qualname = + +[logger_sqlalchemy] +level = WARN +handlers = +qualname = sqlalchemy.engine + +[logger_alembic] +level = INFO +handlers = +qualname = alembic + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(levelname)-5.5s [%(name)s] %(message)s +datefmt = %H:%M:%S diff --git a/migrations/env.py b/migrations/env.py new file mode 100644 index 0000000..79b8174 --- /dev/null +++ b/migrations/env.py @@ -0,0 +1,96 @@ +from __future__ import with_statement + +import logging +from logging.config import fileConfig + +from sqlalchemy import engine_from_config +from sqlalchemy import pool + +from alembic import context + +# this is the Alembic Config object, which provides +# access to the values within the .ini file in use. +config = context.config + +# Interpret the config file for Python logging. +# This line sets up loggers basically. +fileConfig(config.config_file_name) +logger = logging.getLogger('alembic.env') + +# add your model's MetaData object here +# for 'autogenerate' support +# from myapp import mymodel +# target_metadata = mymodel.Base.metadata +from flask import current_app +config.set_main_option( + 'sqlalchemy.url', current_app.config.get( + 'SQLALCHEMY_DATABASE_URI').replace('%', '%%')) +target_metadata = current_app.extensions['migrate'].db.metadata + +# other values from the config, defined by the needs of env.py, +# can be acquired: +# my_important_option = config.get_main_option("my_important_option") +# ... etc. + + +def run_migrations_offline(): + """Run migrations in 'offline' mode. + + This configures the context with just a URL + and not an Engine, though an Engine is acceptable + here as well. By skipping the Engine creation + we don't even need a DBAPI to be available. + + Calls to context.execute() here emit the given string to the + script output. + + """ + url = config.get_main_option("sqlalchemy.url") + context.configure( + url=url, target_metadata=target_metadata, literal_binds=True + ) + + with context.begin_transaction(): + context.run_migrations() + + +def run_migrations_online(): + """Run migrations in 'online' mode. + + In this scenario we need to create an Engine + and associate a connection with the context. + + """ + + # this callback is used to prevent an auto-migration from being generated + # when there are no changes to the schema + # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html + def process_revision_directives(context, revision, directives): + if getattr(config.cmd_opts, 'autogenerate', False): + script = directives[0] + if script.upgrade_ops.is_empty(): + directives[:] = [] + logger.info('No changes in schema detected.') + + connectable = engine_from_config( + config.get_section(config.config_ini_section), + prefix='sqlalchemy.', + poolclass=pool.NullPool, + ) + + with connectable.connect() as connection: + context.configure( + connection=connection, + target_metadata=target_metadata, + process_revision_directives=process_revision_directives, + **current_app.extensions['migrate'].configure_args + ) + + with context.begin_transaction(): + context.run_migrations() + + +if context.is_offline_mode(): + run_migrations_offline() +else: + run_migrations_online() diff --git a/migrations/script.py.mako b/migrations/script.py.mako new file mode 100644 index 0000000..2c01563 --- /dev/null +++ b/migrations/script.py.mako @@ -0,0 +1,24 @@ +"""${message} + +Revision ID: ${up_revision} +Revises: ${down_revision | comma,n} +Create Date: ${create_date} + +""" +from alembic import op +import sqlalchemy as sa +${imports if imports else ""} + +# revision identifiers, used by Alembic. +revision = ${repr(up_revision)} +down_revision = ${repr(down_revision)} +branch_labels = ${repr(branch_labels)} +depends_on = ${repr(depends_on)} + + +def upgrade(): + ${upgrades if upgrades else "pass"} + + +def downgrade(): + ${downgrades if downgrades else "pass"} diff --git a/migrations/versions/6301de4834d1_.py b/migrations/versions/6301de4834d1_.py new file mode 100644 index 0000000..e87730e --- /dev/null +++ b/migrations/versions/6301de4834d1_.py @@ -0,0 +1,55 @@ +"""empty message + +Revision ID: 6301de4834d1 +Revises: +Create Date: 2019-08-17 15:06:22.058512 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '6301de4834d1' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('user', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('username', sa.String(length=64), nullable=False), + sa.Column('email', sa.String(length=120), nullable=False), + sa.Column('password_hash', sa.String(length=128), nullable=False), + sa.Column('is_admin', sa.Boolean(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=True) + op.create_index(op.f('ix_user_username'), 'user', ['username'], unique=True) + op.create_table('episode', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('name', sa.String(length=255), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('joke', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('joke_text', sa.Text(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('joke') + op.drop_table('episode') + op.drop_index(op.f('ix_user_username'), table_name='user') + op.drop_index(op.f('ix_user_email'), table_name='user') + op.drop_table('user') + # ### end Alembic commands ### diff --git a/requirements.txt b/requirements.txt index 7e10602..dfe16f3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,6 @@ -flask +# core +Flask ~= 1.1.1 + +# database +Flask-SQLAlchemy ~= 2.4.0 +flask-migrate ~= 2.5.2 From a2a62bb7aa45a8301e0bef38d33fe30cb26c357d Mon Sep 17 00:00:00 2001 From: Aleksander Date: Sat, 17 Aug 2019 15:12:35 +0300 Subject: [PATCH 07/22] fix config get --- app/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models.py b/app/models.py index 4ad3b34..f944446 100644 --- a/app/models.py +++ b/app/models.py @@ -33,7 +33,7 @@ def get_file_path(self): ''' Return wrapped in jingles file path ''' - static_path = os.path.join(app.config.STATIC_ROOT, 'episodes') + static_path = os.path.join(app.config.get('STATIC_ROOT'), 'episodes') file_path = f'{static_path}/{self.id}.mp3' if os.path.exists(file_path): return file_path From 24a9ae594ab3f060263e4ecdc1471f92f4c8b008 Mon Sep 17 00:00:00 2001 From: Alexander Shustrov Date: Sat, 17 Aug 2019 15:38:26 +0300 Subject: [PATCH 08/22] Edited file methods --- app/models.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models.py b/app/models.py index f944446..afe8f99 100644 --- a/app/models.py +++ b/app/models.py @@ -41,7 +41,7 @@ def get_file_path(self): # todo: add to celery task def generate_wrapped_file(self, upload_file): ''' - Generate file with name of episode prefix from upload_file + Return generate file with name of episode prefix from upload_file ''' pass @@ -63,9 +63,15 @@ def get_file_path(self): if os.path.exists(file_path): return file_path + def generate_base_file(self): + ''' + Return generate base audio file from joke_text + ''' + pass + # todo: add to celery task def generate_wrapped_file(self, upload_file): ''' - Generate wrapped in jingles file from upload_file + Return generate wrapped in jingles file from upload_file ''' pass From 90a736fd09a096bd5ed5fd0b80aa7c652f0ca4a3 Mon Sep 17 00:00:00 2001 From: lex51 Date: Sat, 17 Aug 2019 19:46:03 +0300 Subject: [PATCH 09/22] Delete routes.py --- app/routes.py | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 app/routes.py diff --git a/app/routes.py b/app/routes.py deleted file mode 100644 index 4ee1448..0000000 --- a/app/routes.py +++ /dev/null @@ -1,9 +0,0 @@ -# View functions -from flask import render_template -from app import app - - -@app.route('/') -def index(): - feed_blank = 'Podcast Main page: RSS feed' - return render_template('index.html', feed_blank=feed_blank) From 2344a6c05a330928bcf7f35337ee71e071481471 Mon Sep 17 00:00:00 2001 From: lex51 Date: Sat, 17 Aug 2019 19:52:46 +0300 Subject: [PATCH 10/22] Update models.py --- app/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models.py b/app/models.py index afe8f99..0417898 100644 --- a/app/models.py +++ b/app/models.py @@ -49,10 +49,10 @@ def generate_wrapped_file(self, upload_file): class Joke(db.Model): id = db.Column(db.Integer, primary_key=True) joke_text = db.Column(db.Text, nullable=False) - user_id = db.Column(db.Integer, db.ForeignKey('user.id')) +# user_id = db.Column(db.Integer, db.ForeignKey('user.id')) def __repr__(self): - return f', name: {self.name}' + return f', joke_text: {self.joke_text}' def get_file_path(self): ''' From e49068ede60a89f9801f5194d310c1c8b54893c1 Mon Sep 17 00:00:00 2001 From: lex51 Date: Sat, 17 Aug 2019 19:53:38 +0300 Subject: [PATCH 11/22] Create parser.py --- app/parser.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 app/parser.py diff --git a/app/parser.py b/app/parser.py new file mode 100644 index 0000000..d4a001b --- /dev/null +++ b/app/parser.py @@ -0,0 +1,28 @@ +# parsing jokes from anekdotitut.ru +# +import urllib.request +from urllib.parse import quote +from urllib.parse import unquote +from bs4 import BeautifulSoup +import re +from app.models import Joke +from app import db + + +def parse_anekdot(): + jokes_out = [] + for i in range(1, 10): + url = url = 'https://anekdotitut.ru/pro_armyanskoe_radio' + str( + i) + '.php' + html_doc = urllib.request.urlopen(url) + soup_doc = BeautifulSoup(html_doc, 'html.parser') + jokes = soup_doc.body(class_='noselect', id=re.compile('anekdot\d+')) + for joke in jokes: + jokes_out.append(joke.text) + if not bool(Joke.query.filter_by(joke_text='some_text').first()): + j = Joke(joke_text=joke.text) + db.session.add(j) + db.session.commit() + + # return jokes_out + From 40a8f707d6a1a3871d1486b593503a72344691cd Mon Sep 17 00:00:00 2001 From: lex51 Date: Sun, 18 Aug 2019 11:44:47 +0300 Subject: [PATCH 12/22] Update config.py --- config.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config.py b/config.py index 94849ca..d79af6e 100644 --- a/config.py +++ b/config.py @@ -13,3 +13,5 @@ class Config(object): ADMINS = ['your-email@example.com'] STATIC_ROOT = '/static/' + + PARSE_TIME_HOURS = 40 From 6e3d1be4c7e4a8b1ebe02a1487905afd753e0890 Mon Sep 17 00:00:00 2001 From: lex51 Date: Sun, 18 Aug 2019 11:45:51 +0300 Subject: [PATCH 13/22] Update __init__.py --- app/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/__init__.py b/app/__init__.py index 9ea8fbd..d1b33ae 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -21,3 +21,17 @@ # as it is always done. The bottom import is a workaround to circular imports, # a common problem with Flask applications. from app import routes, models +import atexit +from app.parser import parse_anekdot +from apscheduler.schedulers.background import BackgroundScheduler + +def scheduler_parser(): + + parse_anekdot() + +scheduler = BackgroundScheduler() +scheduler.add_job(func=scheduler_parser, trigger="interval", hour=Config.PARSE_TIME_HOURS) +scheduler.start() + +# Shut down the scheduler when exiting the app +atexit.register(lambda: scheduler.shutdown()) From 65f85be096d7e17c37e4f26c9f4a5f28be0ba331 Mon Sep 17 00:00:00 2001 From: lex51 Date: Sun, 18 Aug 2019 11:47:03 +0300 Subject: [PATCH 14/22] Update models.py --- app/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models.py b/app/models.py index 0417898..1b318cf 100644 --- a/app/models.py +++ b/app/models.py @@ -49,7 +49,7 @@ def generate_wrapped_file(self, upload_file): class Joke(db.Model): id = db.Column(db.Integer, primary_key=True) joke_text = db.Column(db.Text, nullable=False) -# user_id = db.Column(db.Integer, db.ForeignKey('user.id')) + user_id = db.Column(db.Integer, db.ForeignKey('user.id')) def __repr__(self): return f', joke_text: {self.joke_text}' From 45468ba7fb92378cde452daec8a0a4f02e8f2a3c Mon Sep 17 00:00:00 2001 From: lex51 Date: Sun, 18 Aug 2019 11:48:17 +0300 Subject: [PATCH 15/22] Update parser.py --- app/parser.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/parser.py b/app/parser.py index d4a001b..2ae542f 100644 --- a/app/parser.py +++ b/app/parser.py @@ -1,5 +1,4 @@ # parsing jokes from anekdotitut.ru -# import urllib.request from urllib.parse import quote from urllib.parse import unquote @@ -11,18 +10,15 @@ def parse_anekdot(): jokes_out = [] - for i in range(1, 10): + for i in range(1, 11): url = url = 'https://anekdotitut.ru/pro_armyanskoe_radio' + str( i) + '.php' html_doc = urllib.request.urlopen(url) soup_doc = BeautifulSoup(html_doc, 'html.parser') jokes = soup_doc.body(class_='noselect', id=re.compile('anekdot\d+')) for joke in jokes: - jokes_out.append(joke.text) - if not bool(Joke.query.filter_by(joke_text='some_text').first()): - j = Joke(joke_text=joke.text) + # jokes_out.append(joke.text) + if not bool(Joke.query.filter_by(joke_text = joke.text).first()): + j = Joke(joke_text = joke.text, user_id = 999) db.session.add(j) db.session.commit() - - # return jokes_out - From b86798d6b8d1e18d328ef5f4c08ef2e9146eed31 Mon Sep 17 00:00:00 2001 From: lex51 Date: Sun, 18 Aug 2019 11:49:15 +0300 Subject: [PATCH 16/22] Update requirements.txt --- requirements.txt | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index dfe16f3..04c0f32 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,23 @@ -# core -Flask ~= 1.1.1 - -# database -Flask-SQLAlchemy ~= 2.4.0 -flask-migrate ~= 2.5.2 +alembic==1.0.11 +Click==7.0 +dominate==2.4.0 +Flask==1.1.1 +Flask-Bootstrap==3.3.7.1 +Flask-Login==0.4.1 +Flask-Migrate==2.5.2 +Flask-SQLAlchemy==2.4.0 +Flask-WTF==0.14.2 +itsdangerous==1.1.0 +Jinja2==2.10.1 +Mako==1.1.0 +MarkupSafe==1.1.1 +pydub==0.23.1 +python-dateutil==2.8.0 +python-editor==1.0.4 +six==1.12.0 +SQLAlchemy==1.3.7 +visitor==0.1.3 +Werkzeug==0.15.5 +WTForms==2.2.1 +beautifulsoup4==4.7.1 +APScheduler==3.6.1 From a1022e50946db58b85a612f66cd36c2b57275860 Mon Sep 17 00:00:00 2001 From: lex51 Date: Sun, 18 Aug 2019 16:59:16 +0300 Subject: [PATCH 17/22] Update parser.py --- app/parser.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/parser.py b/app/parser.py index 2ae542f..69dd18e 100644 --- a/app/parser.py +++ b/app/parser.py @@ -1,4 +1,5 @@ -# parsing jokes from anekdotitut.ru +# Parsing jokes from anekdotitut.ru and adds +# them to the database. import urllib.request from urllib.parse import quote from urllib.parse import unquote @@ -9,16 +10,20 @@ def parse_anekdot(): + ''' + Simple func for collecting jokes from anekdotitut.ru + and add them to DB. + ''' jokes_out = [] - for i in range(1, 11): + for i in range(1, 10): url = url = 'https://anekdotitut.ru/pro_armyanskoe_radio' + str( i) + '.php' html_doc = urllib.request.urlopen(url) soup_doc = BeautifulSoup(html_doc, 'html.parser') jokes = soup_doc.body(class_='noselect', id=re.compile('anekdot\d+')) for joke in jokes: - # jokes_out.append(joke.text) + # Check for entry in DB. if not bool(Joke.query.filter_by(joke_text = joke.text).first()): j = Joke(joke_text = joke.text, user_id = 999) db.session.add(j) - db.session.commit() + db.session.commit() From 6c6e001e1ac2b63d74145641b72b7a47f6291adb Mon Sep 17 00:00:00 2001 From: lex51 Date: Sun, 18 Aug 2019 17:01:10 +0300 Subject: [PATCH 18/22] Update __init__.py --- app/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/__init__.py b/app/__init__.py index d1b33ae..8fbd155 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -26,12 +26,17 @@ from apscheduler.schedulers.background import BackgroundScheduler def scheduler_parser(): - + ''' + Starts the parser. + ''' parse_anekdot() +# Scheduler settings and start. +# Variables locate in config.Config scheduler = BackgroundScheduler() scheduler.add_job(func=scheduler_parser, trigger="interval", hour=Config.PARSE_TIME_HOURS) scheduler.start() # Shut down the scheduler when exiting the app atexit.register(lambda: scheduler.shutdown()) + From f72afa6e1e9ae414b941eaf55b275b6ee22cf406 Mon Sep 17 00:00:00 2001 From: lex51 Date: Sun, 18 Aug 2019 17:02:18 +0300 Subject: [PATCH 19/22] Update config.py --- config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/config.py b/config.py index d79af6e..12e51ca 100644 --- a/config.py +++ b/config.py @@ -14,4 +14,5 @@ class Config(object): STATIC_ROOT = '/static/' + # Time period for parser PARSE_TIME_HOURS = 40 From af3783a1ad55184759118ad66dde62ec5bbbcb68 Mon Sep 17 00:00:00 2001 From: dschglv Date: Sun, 18 Aug 2019 21:54:26 +0300 Subject: [PATCH 20/22] change parameter --- app.db | Bin 32768 -> 53248 bytes app/__init__.py | 3 ++- app/parser.py | 3 ++- 3 files changed, 4 insertions(+), 2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Rr1xP^=OqeBx@xorNPz&&E&ZzN# zLa(|Fp+Bt9a}#cTDP@o?5(3FAI*E&8Fy}{BP$QKJ=MiX7srZIK3a4iDY6Ln)tqDkS zt1J56Pg2N-eiw-@AA<2+iu*zo(qM+Z?BmN7ZN!1ySXoCh(Ldz|cZ z#8LyQa5R=@Pd@;sPi#c0lv1zFx+0gDL{m;?hUbk^k`F-D5hp;B!70BDYDtj+kgn!` ts1Au3Q#UYW1@mRkfCQ_wJ~K*{-Oi{0C1`Ys{jB1 diff --git a/app/__init__.py b/app/__init__.py index 8fbd155..3a39a44 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -33,8 +33,9 @@ def scheduler_parser(): # Scheduler settings and start. # Variables locate in config.Config + scheduler = BackgroundScheduler() -scheduler.add_job(func=scheduler_parser, trigger="interval", hour=Config.PARSE_TIME_HOURS) +scheduler.add_job(func=scheduler_parser, trigger="interval", minutes=60 * Config.PARSE_TIME_HOURS) scheduler.start() # Shut down the scheduler when exiting the app diff --git a/app/parser.py b/app/parser.py index 69dd18e..8793c9f 100644 --- a/app/parser.py +++ b/app/parser.py @@ -26,4 +26,5 @@ def parse_anekdot(): if not bool(Joke.query.filter_by(joke_text = joke.text).first()): j = Joke(joke_text = joke.text, user_id = 999) db.session.add(j) - db.session.commit() + print(joke.joke_text) + db.session.commit() \ No newline at end of file From cc5ba48d174e5e8b015db93be0082601e6c854c6 Mon Sep 17 00:00:00 2001 From: dschglv Date: Sun, 18 Aug 2019 21:55:50 +0300 Subject: [PATCH 21/22] change parameter --- app/parser.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/parser.py b/app/parser.py index 8793c9f..464f5c4 100644 --- a/app/parser.py +++ b/app/parser.py @@ -26,5 +26,4 @@ def parse_anekdot(): if not bool(Joke.query.filter_by(joke_text = joke.text).first()): j = Joke(joke_text = joke.text, user_id = 999) db.session.add(j) - print(joke.joke_text) db.session.commit() \ No newline at end of file From 94c12f2faeb5019189c3d82dba38b55ec647517c Mon Sep 17 00:00:00 2001 From: dschglv Date: Sun, 18 Aug 2019 22:03:37 +0300 Subject: [PATCH 22/22] change parameter --- app/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 3a39a44..d049118 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -20,7 +20,7 @@ # The routes module is imported at the bottom and not at the top of the script # as it is always done. The bottom import is a workaround to circular imports, # a common problem with Flask applications. -from app import routes, models +from app import models import atexit from app.parser import parse_anekdot from apscheduler.schedulers.background import BackgroundScheduler @@ -35,7 +35,7 @@ def scheduler_parser(): # Variables locate in config.Config scheduler = BackgroundScheduler() -scheduler.add_job(func=scheduler_parser, trigger="interval", minutes=60 * Config.PARSE_TIME_HOURS) +scheduler.add_job(func=scheduler_parser, trigger="interval", hours=Config.PARSE_TIME_HOURS) scheduler.start() # Shut down the scheduler when exiting the app