def post(self): text = fileToText(self.request.get("data")) if text == None: self.redirect('/ramble') return text = unicodedata.normalize('NFKD', text).encode('ascii', 'ignore') wordList = filterFillers(text) emotions = find_emotions(wordList) topemotions = top_emotions(emotions) #returns a list of top emotions rgb_1 = topemotions["first"] rgb_2 = topemotions["second"] full_text = " " full_text = full_text.join(wordList) user = users.get_current_user() email_address = user.nickname() if user: #not tested yet now = datetime.utcnow() newJournal = Journal( user=email_address, text=full_text, rgb1=rgb_1, rgb2=rgb_2, year=int(now.year), month=int(now.month), sumSeconds=(int((now.day * 60 * 24 * 60) + (now.hour * 60 * 60) + (now.minute * 60) + (now.second)))) newJournal.put() time.sleep(LATENCY_TIME) self.redirect("/slider?key=" + str(newJournal.year) + " " + str(newJournal.month) + " " + str(newJournal.sumSeconds))
def delete_entry(journal_id): if not request.form['_METHOD'] == 'DELETE': flash('ERROR 405 METHOD NOT ALLOWED', 'error') return redirect(url_for('index')) Journal.delete_record(journal_id) flash(f'Successfully deleted {journal_id}', 'success') return redirect(url_for('index'))
def test_journal_creation(self): """Create Journal / 1 Entry""" self.create_users() user = User.select().get() Journal.create(user=user, title='Space', date='2018-10-12', time_spent=12, learned='Test', resources='Test') journal = Journal.select().get() self.assertEqual(Journal.select().count(), 1) self.assertEqual(journal.user, user)
def __get_expanded_tuples(inner_table): sql = """ with ids as ({0}) select a.id, a.name, a.affiliation, pa.authorid, pa.paperid, pa.name, pa.affiliation, p.id, p.title, p.year, p.keyword, c.id, c.shortname, c.fullname, j.id, j.shortname, j.fullname from ids inner join paperauthor pa on ids.authorid = pa.authorid and ids.paperid = pa.paperid inner join author a on pa.authorid = a.id inner join paper p on pa.paperid = p.id left join conference c on p.conferenceid = c.id left join journal j on p.journalid = j.id """.format(inner_table) build_from_row = lambda r: Expanded(author=Author._make(r[0:3]) if r[0] else None, paperauthor=PaperAuthor._make(r[3:7]) if r[3] and r[4] else None, paper=Paper._make(r[7:11]) if r[7] else None, conference=Conference._make(r[11:14]) if r[11] else None, journal=Journal._make(r[14:17]) if r[14] else None) return [build_from_row(r) for r in __execute_sql(sql)]
def get(self): # key = self.request.get_all("key") # name= key[0].split(' ') user = users.get_current_user() email_address = user.nickname() profilePerson = Person.query().filter(Person.email == email_address).get() # gets the right obj now!! journal_query = Journal.query().filter(Journal.user == email_address).order(-Journal.created).fetch() # try w data journal_dates = [] journal_times = [] journal_keys = [] for journal in journal_query: now = journal.created str_day = now.strftime('%m-%d-%Y') str_time = now.strftime('%H:%M') str_key = str(now.year) + " " + str(now.month) + " " + str(journal.sumSeconds) journal_dates.append(str_day) journal_times.append(str_time) journal_keys.append(str_key) #goal - when you click profile, it populates it with the profile of the person you clicked on/ yourself acct_dict={ "firstName": profilePerson.first_name, "lastName": profilePerson.last_name, #finish this!! "journal_query": journal_query, "journal_dates": journal_dates, "journal_times": journal_times, "journal_keys": journal_keys, } acct_template = jinja_env.get_template("/templates/account.html") checkLogIn(acct_dict) self.response.write(acct_template.render(acct_dict))
def perform_task(request): context = { 'today': date.today().strftime('%Y-%m-%d'), 'room_list': Room.objects.all(), 'flatmate_list': Flatmate.objects.all() } try: flatmate_id = request.POST['flatmate'] except (KeyError, Flatmate.DoesNotExist): return render(request, 'wgapp/task_perform.html', context) try: task_id = request.POST.getlist('task') except (KeyError, Task.DoesNotExist): return render(request, 'wgapp/task_perform.html', context) else: date_input = request.POST['date'] flatmate = Flatmate.objects.get(pk=flatmate_id) for t in task_id: task = Task.objects.get(pk=t) tj = Journal() tj.task = task tj.done_by = flatmate tj.done_on = datetime.strptime(date_input, '%Y-%m-%d') tj.save() # Always return an HttpResponseRedirect after successfully dealing # with POST data. This prevents data from being posted twice if a # user hits the Back button. return HttpResponseRedirect(reverse('wgapp:journal_list', ))
def bounce(sender, recipient, text, is_jailed=False, *args, **kwawrs): """ main bounce worker """ from models import Journal log = bounce.get_logger() log.debug('From=%s To %s (jailed=%s)' % (sender, recipient, is_jailed)) #: First of all, save messa to the Journal journal = None try: journal = Journal(sender=sender, recipient=recipient, is_jailed=is_jailed, text=text) journal.save() except Exception, e: log.debug(str(e))
def bounce(sender,recipient,text,is_jailed=False,*args,**kwawrs): """ main bounce worker """ from models import Journal log= bounce.get_logger() log.debug('From=%s To %s (jailed=%s)' % (sender,recipient,is_jailed) ) #: First of all, save messa to the Journal journal=None try: journal=Journal( sender=sender, recipient=recipient, is_jailed=is_jailed, text=text) journal.save() except Exception,e: log.debug( str(e) )
def create(): journal_entry = request.form.to_dict(flat=True) journal_entry_copy = copy.deepcopy(journal_entry) for key, val in journal_entry_copy.items(): if not bool(val): journal_entry.pop(key, None) entry_id, is_error = Journal.create_record(journal_entry) if is_error: flash('Error occured while Creating entry', 'error') return redirect(url_for('index')) return redirect(url_for('details', journal_id=str(entry_id)))
def add_journal(title, filename, tags, file_location): result = os.popen(f'ipfs add {file_location}') hash = result.read().split()[1] new_journal = Journal(hash=hash, url=file_location, filename=filename, keywords=tags, title=title) db.session.add(new_journal) db.session.commit() send_for_approval(f'j{new_journal.id}')
def perform_task(request): context = {'today': date.today().strftime('%Y-%m-%d'), 'room_list': Room.objects.all(), 'flatmate_list': Flatmate.objects.all()} try: flatmate_id = request.POST['flatmate'] except(KeyError, Flatmate.DoesNotExist): return render(request, 'wgapp/task_perform.html', context) try: task_id = request.POST.getlist('task') except(KeyError, Task.DoesNotExist): return render(request, 'wgapp/task_perform.html', context) else: date_input = request.POST['date'] flatmate = Flatmate.objects.get(pk=flatmate_id) for t in task_id: task = Task.objects.get(pk=t) tj = Journal() tj.task = task tj.done_by = flatmate tj.done_on = datetime.strptime(date_input, '%Y-%m-%d') tj.save() # Always return an HttpResponseRedirect after successfully dealing # with POST data. This prevents data from being posted twice if a # user hits the Back button. return HttpResponseRedirect(reverse('wgapp:journal_list',))
def createNewJournal(request): title = request.POST['j_t'] content = request.POST['j_c'] a_id = request.POST['a_id'] author = request.POST['author'] editor = request.POST['editor'] ac = Activity.objects.get(id=a_id) detail = detailContent() detail.DC_title = title detail.DC_html = content detail.DC_author = author detail.DC_editor = editor detail.save() #record record = recordInfo() record.save() new_journal = Journal() new_journal.detail = detail new_journal.school = ac.school new_journal.record = record new_journal.save() ac.journal = new_journal ac.save() createGlobalNews(a_id,new_journal.id,'4') return HttpResponse('1')
def update(journal_id): if not request.form['_METHOD'] == 'PUT': flash('ERROR 405 METHOD NOT ALLOWED', 'error') return redirect(url_for('index')) updated_journal_entry = request.form.to_dict(flat=True) updated_journal_entry.pop('_METHOD', None) err_msg, is_error = \ Journal.update_record(journal_id, updated_journal_entry) if is_error: flash(f'Could not Update! {err_msg}', 'error') else: flash(f'Successfully Updated Journal {journal_id}', 'success') return redirect(url_for('index'))
async def get_journals_list() -> ModelSelect: """Получаем список журналов с их обозначениями, проверяем не появилось ли чего-то нового (скорее всего нет, но функция в первую очередь необходима при первичном запуске приложения) """ page_source = await get_page_source( f"{MAIN_URL}/ru/публикации/журналы/") soup = BeautifulSoup(page_source, 'lxml') journal_filter = soup.find('select', {'id': 'pubFilter'}) for item in journal_filter.find_all('option'): if item['value']: if not Journal.get_or_none(Journal.symbol == item['value']): journal = Journal.create(symbol=item['value'], title=item.text, priority=int( item['data-priority'])) journal.save() logger.debug(f"New journal created: {item.text}") else: logger.debug(f"Parsed journal: {item.text}") return Journal.select()
async def select_journal(user: User, message: Message): callback_data = {} keyboard = InlineKeyboardMarkup() for journal in Journal.select(): if len(journal.issues) == 0: continue callback_data['action'] = 'select_journal_year' callback_data['journal_id'] = journal.id # Сторожевая башня keyboard.add( InlineKeyboardButton(text=journal.title, callback_data=json.dumps(callback_data))) await bot.send_message(user.user_id, 'Какой журнал Вас интересует?', reply_markup=keyboard)
async def main(broker_account_id=None): balance = 10000 amount = 20 journal = Journal(mode='debug') traider = Traider(balance, journal, amount) analysis = Analysis(journal) stock = Stock(traider, journal) client = ti.AsyncClient(TOKEN, use_sandbox=True) data = await get_data(client, figi) print('Amount of data:', len(data)) df = pd.DataFrame(data) df.set_index('date', inplace=True) traider.trade(df, strategy=StrategyMACD_Day(loss_level=loss, profit_level=profit, macd_level=macd_level, target_stability=target_stability)) stock.interval_trade(df[-1:]) analysis.score() no_update = True async with ti.Streaming(TOKEN, receive_timeout=20, reconnect_timeout=10, heartbeat=20) as streaming: await streaming.candle.subscribe(figi, ti.CandleResolution.min5) async for event in streaming: if event.event == 'candle': pass # print(event.payload.figi, event.payload.c, event.payload.interval, event.payload.h, event.payload.time) if not (event.payload.time.strftime('%e-%m-%Y %H:%M') == data[-1]['date']) and no_update: no_update = False data = await get_data(client, figi) df = pd.DataFrame(data) df.set_index('date', inplace=True) traider.trade(df, strategy=StrategyMACD_Day( loss_level=loss, profit_level=profit, macd_level=macd_level, target_stability=target_stability)) stock.interval_trade(df[-1:]) analysis.score() elif event.payload.time.strftime( '%e-%m-%Y %H:%M') == data[-1]['date']: no_update = True
def journalize(sender, recipient, text, is_jailed=False, *args, **kwawrs): """ recourde bounce mail """ from models import Journal logger.debug( 'paloma.tasks.journalize:From=%s To %s (jailed=%s)' % ( sender, recipient, is_jailed)) #: First of all, save message to the Journal journal = None try: journal = Journal( sender=sender, recipient=recipient, is_jailed=is_jailed, text=text) journal.save() except Exception: _traceback("paloma.tasks.journalize:", traceback.format_exc()) return journal and journal.id
def post(self): time_key = self.request.get('key_value') timeKeyString = unicodedata.normalize('NFKD', time_key).encode('ascii','ignore') timeKeyList = timeKeyString.split(" ") year = int(timeKeyList[0]) month = int(timeKeyList[1]) sumofSeconds = int(timeKeyList[2]) user = users.get_current_user() email_address = user.nickname() profilePerson = Person.query().filter(Person.email == email_address).get() journal_page = Journal.query().filter(Journal.user == email_address).filter(Journal.year == year).filter(Journal.month == month).filter(Journal.sumSeconds >= sumofSeconds).get() journal_page.key.delete() time.sleep(LATENCY_TIME) self.redirect('/account')
def new_journal_from_search(username, park_code): """Show form for adding a new journal with park already chosen (GET) or add journal to db and go to user page (POST)""" # Check if logged in user is this user if is_correct_user(username): form = NewJournalForm() # Get park_code and name from db table for select field in form park = Park.query.get_or_404(park_code) form.park_name.choices = [(park_code, park.park_name)] if form.validate_on_submit(): date_added = datetime.now() date_of_visit = form.date_of_visit.data user_id = user_id title = form.title.data text = form.text.data park_code = form.park_name.data title_img_url = form.title_img_url.data journal = Journal(date_added=date_added, date_of_visit=date_of_visit, user_id=user_id, title=title, text=text, park_code=park_code, title_img_url=title_img_url) db.session.add(journal) db.session.commit() visit = Visit(date_of_visit=date_of_visit, user_id=user_id, park_code=park_code, journal_id=journal.id) db.session.add(visit) db.session.commit() flash("Journal successfully created") # on successful creation, redirect to users page return redirect(f"/users/{ user.username }") return render_template("new_journal.html", form=form) flash("Not your dashboard") return redirect("/")
async def select_journal_year(user: User, data: dict): keyboard = InlineKeyboardMarkup(row_width=2) journal = Journal.get(Journal.id == data['journal_id']) for journal_issue in (JournalIssue.select(JournalIssue.year).where( JournalIssue.journal == journal).distinct().order_by( JournalIssue.year.desc())): callback_data = { 'action': 'select_issue', 'journal_id': data['journal_id'], 'year': journal_issue.year } n = len(json.dumps(callback_data)) keyboard.add( InlineKeyboardButton(text=journal_issue.year, callback_data=json.dumps(callback_data))) await bot.send_message(user.user_id, 'Выберите год:', reply_markup=keyboard)
async def select_issue(user: User, data: dict): keyboard = InlineKeyboardMarkup(row_width=2) journal = Journal.get(Journal.id == data['journal_id']) year = data.get('year', 2021) for journal_issue in JournalIssue.select().where( JournalIssue.journal == journal, JournalIssue.year == year).order_by(JournalIssue.number): if len(journal_issue.articles) == 0: continue callback_data = { # max length 64 symbols 'action': 'select_article', 'journal_issue_id': journal_issue.id } keyboard.add( InlineKeyboardButton( text=f"№{journal_issue.number}|{journal_issue.title}", callback_data=json.dumps(callback_data))) await bot.send_message(user.user_id, 'Выберите номер журнала:', reply_markup=keyboard)
def get_journal_id(record, created_by, date_created): journal_abbr = record.get('journal_abbrev', '') journal_full_name = record.get('journal_title', '') issn_print = record.get('issn_print') issn_electronic = record.get('issn_electronic') if issn_print: journals = DBSession.query(Journal).filter_by( issn_print=issn_print).all() if len(journals) > 0: return journals[0].journal_id, journals[ 0].med_abbr, journal_full_name, issn_print if journal_abbr: journals = DBSession.query(Journal).filter_by( med_abbr=journal_abbr).all() if len(journals) > 0: return journals[0].journal_id, journals[ 0].med_abbr, journal_full_name, issn_print source_id = 824 # 'PubMed' # format_name = journal_full_name.replace(' ', '_') + journal_abbr.replace(' ', '_') journal_full_name = journal_full_name.split(" : ")[0] format_name = journal_full_name.replace(' ', '_') j = Journal(issn_print=issn_print, issn_electronic=issn_electronic, display_name=journal_full_name, format_name=format_name, title=journal_full_name, med_abbr=journal_abbr, source_id=source_id, obj_url='/journal/' + format_name, date_created=date_created, created_by=created_by) DBSession.add(j) DBSession.flush() DBSession.refresh(j) return j.journal_id, j.med_abbr, journal_full_name, issn_print
def add_journal(self, created, from_wallet_id, to_wallet_id, type_operation): """ Добавление записи в журнал :param created: Время записи :param from_wallet_id: От кого :param to_wallet_id: Кому :param type_operation: Тип события :return: Результат выполнения функции (Строка) """ try: journal = Journal(created=created, from_wallet_id=from_wallet_id, to_wallet_id=to_wallet_id, type_operation=type_operation) self.session.add(journal) self.session.flush() self.session.commit() return 'ОК.' except: return 'ERROR.'
import os import time from random import randint from models import Journal LEVEL_CHOICE = [10, 20, 30, 40, 50] count = int(os.environ.get("ITERATIONS", "1000")) maxval = count - 1 count *= 2 start = time.time() for _ in range(count): val = randint(1, maxval) Journal.get(Journal.id == val) now = time.time() print(f"peewee, F: Rows/sec: {count / (now - start): 10.2f}")
import time from models import Journal LEVEL_CHOICE = [10, 20, 30, 40, 50] start = time.time() count = 0 for _ in range(10): for level in LEVEL_CHOICE: res = list(Journal.select().where(Journal.level == level)) count += len(res) now = time.time() print(f"peewee, D: Rows/sec: {count / (now - start): 10.2f}")
import os import time from random import choice from models import Journal from pony.orm import commit, db_session LEVEL_CHOICE = [10, 20, 30, 40, 50] count = int(os.environ.get("ITERATIONS", "1000")) start = now = time.time() with db_session(): for i in range(count): Journal(level=choice(LEVEL_CHOICE), text=f"Insert from B, item {i}") commit() now = time.time() print(f"Pony ORM, B: Rows/sec: {count / (now - start): 10.2f}")
import os import time from random import choice from models import Journal LEVEL_CHOICE = [10, 20, 30, 40, 50] CHUNK_SIZE = 100 count = int(os.environ.get('ITERATIONS', '1000')) # Work around peewee bulk-insert limitation that is total of 2000 values test = int(os.environ.get('TEST', '1')) if test == 3: CHUNK_SIZE = 50 chunks = count // CHUNK_SIZE start = now = time.time() for _ in range(chunks): Journal.insert_many([(choice(LEVEL_CHOICE), f'Insert from C, item {i}') for i in range(CHUNK_SIZE)], [Journal.level, Journal.text]).execute() now = time.time() print(f'peewee, C: Rows/sec: {count / (now - start): 10.2f}')
import os import time from random import choice from models import Journal, engine from sqlalchemy.orm import sessionmaker LEVEL_CHOICE = [10, 20, 30, 40, 50] count = int(os.environ.get('ITERATIONS', '1000')) Session = sessionmaker(bind=engine) start = now = time.time() session = Session() for i in range(count): session.add(Journal( level=choice(LEVEL_CHOICE), text=f'Insert from A, item {i}' )) session.commit() now = time.time() print(f'SQLAlchemy ORM, A: Rows/sec: {count / (now - start): 10.2f}')
import time from models import Journal LEVEL_CHOICE = [10, 20, 30, 40, 50] start = time.time() count = 0 for _ in range(10): for level in LEVEL_CHOICE: res = list(Journal.select().where(Journal.level == level).tuples()) count += len(res) now = time.time() print(f'peewee, H: Rows/sec: {count / (now - start): 10.2f}')
import os import time from random import choice from models import Journal, conn LEVEL_CHOICE = [10, 20, 30, 40, 50] count = int(os.environ.get('ITERATIONS', '1000')) start = now = time.time() trans = conn.transaction() for i in range(count): Journal(level=choice(LEVEL_CHOICE), text=f'Insert from B, item {i}', connection=trans) trans.commit(close=True) now = time.time() print(f'SQLObject, B: Rows/sec: {count / (now - start): 10.2f}')
def get(self): key = self.request.get_all("key") #this gives you a string print(key) keyString = unicodedata.normalize('NFKD', key[0]).encode('ascii', 'ignore') keyList = keyString.split(" ") year = int(keyList[0]) month = int(keyList[1]) sumofSeconds = int(keyList[2]) #'2019', '10', '1119957'] user = users.get_current_user() email_address = user.nickname() print(email_address) profilePerson = Person.query().filter( Person.email == email_address).get() time.sleep(5) journal_page = Journal.query().filter( Journal.user == email_address).filter(Journal.year == year).filter( Journal.month == month).filter( Journal.sumSeconds == sumofSeconds).get() now = journal_page.created str_day = now.strftime('%m-%d-%Y') str_time = now.strftime('%H:%M') emotions = find_emotions(text_to_list(journal_page.text)) totalEmotions = 0 for emotion in emotions: totalEmotions += emotions[emotion] percent_emotions = {} if totalEmotions != 0: percent_emotions["angry"] = round( 100 * (emotions["angry"] / totalEmotions)) percent_emotions["sad"] = round(100 * (emotions["sad"] / totalEmotions)) percent_emotions["happy"] = round( 100 * (emotions["happy"] / totalEmotions)) percent_emotions["worried"] = round( 100 * (emotions["worried"] / totalEmotions)) percent_emotions["confused"] = round( 100 * (emotions["confused"] / totalEmotions)) percent_emotions["embarrassed"] = round( 100 * (emotions["embarrassed"] / totalEmotions)) percent_emotions["tired"] = round( 100 * (emotions["tired"] / totalEmotions)) else: percent_emotions["angry"] = 0 percent_emotions["sad"] = 0 percent_emotions["happy"] = 0 percent_emotions["worried"] = 0 percent_emotions["confused"] = 0 percent_emotions["embarrassed"] = 0 percent_emotions["tired"] = 0 linkpart = str(year) + " " + str(month) + " " + str(sumofSeconds) link = ("/journal?key=" + linkpart) # print(link) s_dict = { "first_name": profilePerson.first_name, "last_name": profilePerson.last_name, "diary_entry": journal_page.text, "r1": journal_page.rgb1[0], "g1": journal_page.rgb1[1], "b1": journal_page.rgb1[2], "r2": journal_page.rgb2[0], "g2": journal_page.rgb2[1], "b2": journal_page.rgb2[2], "date": str_day, "time": str_time, "link": link, "angry": percent_emotions["angry"], "sad": percent_emotions["sad"], "happy": percent_emotions["happy"], "worried": percent_emotions["worried"], "confused": percent_emotions["confused"], "embarrassed": percent_emotions["embarrassed"], "tired": percent_emotions["tired"], } s_template = jinja_env.get_template("/templates/slider.html") self.response.write(s_template.render(s_dict))
import os import time from random import choice from models import Journal LEVEL_CHOICE = [10, 20, 30, 40, 50] count = int(os.environ.get('ITERATIONS', '1000')) start = now = time.time() for i in range(count): Journal(level=choice(LEVEL_CHOICE), text=f'Insert from A, item {i}').save() now = time.time() print(f'peewee, A: Rows/sec: {count / (now - start): 10.2f}')
import time from random import choice from models import Journal, db LEVEL_CHOICE = [10, 20, 30, 40, 50] objs = list(Journal.select()) count = len(objs) start = time.time() with db.atomic(): for obj in objs: obj.level = choice(LEVEL_CHOICE) obj.save(only=['level']) now = time.time() print(f'peewee, J: Rows/sec: {count / (now - start): 10.2f}')
import os import time from random import randrange from models import Journal LEVEL_CHOICE = [10, 20, 30, 40, 50] iters = int(os.environ.get('ITERATIONS', '1000')) start = time.time() count = 0 for _ in range(iters // 10): for level in LEVEL_CHOICE: res = list(Journal.select().where( Journal.level == level).limit(20).offset(randrange(iters - 20))) count += len(res) now = time.time() print(f'peewee, E: Rows/sec: {count / (now - start): 10.2f}')