def handle_xml(self, shows): for country in shows: for i, show in enumerate(country): showid = get_int(show, "showid") show_name = get_str(show, "showname") show, created = Show.get_or_create(title=show_name) if not show.fully_populated: taskqueue.add(url=webapp.uri_for(name_prefix+"show_task"), params={'showid': showid}) if i>12: break
def is_changed(update): log.info(log_msg(update)) # check if user exist in DB. If not - create username = update.effective_user.username user_id = update.effective_user.id full_name = update.effective_user.full_name user, created = UserName.get_or_create(user_id=user_id) Show.get_or_create(user_id=user_id) if not created: # check if user changed own name attributes. If so - update if user.username != username or user.full_name != full_name: user.username = username user.full_name = full_name user.updated = datetime.now().strftime('%y.%m.%d %H:%M:%S.%f')[:-4] user.save() else: user.username = username user.full_name = full_name user.save()
def _new_show(self, rss_url, publisher, feed): description = feed.get('description') or feed.get('summary') image_url = feed.get('image', {}).get('href') \ or feed.get('logo') \ or feed.get('icon') show_dict = { 'publisher': publisher, 'name': self._sanitize_title(feed.get('title')), 'description': self._sanitize_text(description), 'homepage_url': self._sanitize_url(feed.get('link')), 'image_url': self._sanitize_url(image_url), 'language': self._sanitize_word(feed.get('language')) } show_dict = {key: value for key, value in show_dict.iteritems() if value is not None} show, is_new = Show.get_or_create(rss_url=rss_url, defaults=show_dict) print('Saved show "{}": new={}'.format(show_dict['name'], is_new)) return show
def _new_show(self, rss_url, publisher, feed): description = feed.get('description') or feed.get('summary') image_url = feed.get('image', {}).get('href') \ or feed.get('logo') \ or feed.get('icon') show_dict = { 'publisher': publisher, 'name': self._sanitize_title(feed.get('title')), 'description': self._sanitize_text(description), 'homepage_url': self._sanitize_url(feed.get('link')), 'image_url': self._sanitize_url(image_url), 'language': self._sanitize_word(feed.get('language')) } show_dict = { key: value for key, value in show_dict.iteritems() if value is not None } show, is_new = Show.get_or_create(rss_url=rss_url, defaults=show_dict) print('Saved show "{}": new={}'.format(show_dict['name'], is_new)) return show