def _episode(patient, procedure, users): episode_type = random.choice(list(EpisodeType)) d = _date_of_surgery(1) if episode_type == EpisodeType.Surgery: surgery = _surgery(procedure) else: surgery = None e = Episode( episode_type=episode_type, date=d, patient=patient, hospital=patient.hospital, surgery=surgery, complications=[Complication(date=d, comments="It's complicated...")], created_by=random.choice(users), updated_by=random.choice(users), ) attendees = [] for user in users: attendees.append(EpisodeAttendee(user_id=user.id, episode_id=e.id)) e.attendees = attendees return e
def add_show(id): zipped = requests.get("%s/%s/series/%s/all/en.zip" % (API_PATH, settings.TVDB_API_KEY, id)).content content = zipfile.ZipFile(BytesIO(zipped)).read("en.xml") xml = etree.fromstring(content) series = xml.find("Series") name = series.find("SeriesName").text banner = series.find("banner") if banner is None: banner = "" else: banner = banner.text status = series.find("Status").text first_aired = series.find("FirstAired") if first_aired is not None: first_aired = datetime.strptime(first_aired.text, "%Y-%m-%d") imdb = series.find("IMDB_ID") if imdb is None: imdb = "" else: imdb = imdb.text try: show = Show.objects.get(tvdbid=id) show.tvdbid = id show.name = name show.status = status show.banner = banner show.first_aired = first_aired show.imdb = imdb except Show.DoesNotExist: show = Show(tvdbid=id, name=name, status=status, banner=banner, first_aired=first_aired, imdb=imdb) show.save() for e in xml.findall("Episode"): season_number = e.find("SeasonNumber").text if season_number == "0": # Ignore specials for now continue try: season = Season.objects.get(show=show, number=season_number) except Season.DoesNotExist: season = Season(number=season_number, show=show) season.save() episode_number = e.find("EpisodeNumber").text first_aired = datetime.strptime(e.find("FirstAired").text, "%Y-%m-%d") try: episode = Episode.objects.get(number=episode_number, season=season) episode.air_date = first_aired except Episode.DoesNotExist: episode = Episode(number=episode_number, air_date=first_aired, season=season) episode.save() return show
def initialize_database(self): '''Remplissage de la base de données''' #On vérifie si la database est déjà remplie en regardant si on a déjà une série dedans if Episode.query.first() is None: for i in range(200): dictionnaire_episode = {} id = self.__list_id_serie[i] #On créé l'objet dans la base de données dictionnaire_serie = self.get_information_serie(id) serie = Serie(id_serie=dictionnaire_serie['id_serie'], name=dictionnaire_serie['name'], nb_season=dictionnaire_serie['nb_season'], genre=dictionnaire_serie['genre'], start_date=dictionnaire_serie['start_date'], summary=dictionnaire_serie['summary'], realisateur=dictionnaire_serie['realisateur'], name_act=dictionnaire_serie['name_act'], url_picture_tvshow=dictionnaire_serie[ 'url_picture_tvshow'], status=dictionnaire_serie['status']) self.add_in_database(serie) #On parcourt ensuite les saisons de la série for i in range(1, dictionnaire_serie['nb_season'] + 1): dictionnaire_saison = self.get_information_saison(id, i) #On crée les objets associés dans la base de données saison = Saison( id='{}-{}'.format(dictionnaire_saison['id_serie'], dictionnaire_saison['id_saison']), id_saison=dictionnaire_saison['id_saison'], id_serie=dictionnaire_saison['id_serie'], nb_episode=dictionnaire_saison['nb_episode'], url_picture_season=dictionnaire_saison[ 'url_picture_season']) self.add_in_database(saison) #On parcourt les épisodes de la saison for j in range(1, dictionnaire_saison['nb_episode'] + 1): dictionnaire_episode = self.get_information_episode( id, i, j) #On crée les objets associés dans la base de données episode = Episode( id='{}-{}-{}'.format( dictionnaire_episode['id_serie'], dictionnaire_episode['id_saison'], dictionnaire_episode['id_ep']), id_ep=dictionnaire_episode['id_ep'], ep_name=dictionnaire_episode['ep_name'], ep_date=dictionnaire_episode['ep_date'], ep_sum=dictionnaire_episode['ep_sum'], id_saison=dictionnaire_episode['id_saison']) self.add_in_database(episode) db.session.remove()
def create_episode(): if not request.json or not 'title' in request.json: abort(400) data = request.json title = data.get('title') description = data.get('description') episode = (title, description) e = Episode(title=title, description=description) db.session.add(e) db.session.commit() return jsonify({'episode': episode}), 201
def episode_create(): episode = Episode() form = EpisodeEditForm(obj=episode) form.hospital_id.choices = _hospital_id_choices() form.patient_id.choices = _patient_id_choices() if form.validate_on_submit(): episode.episode_type = form.episode_type.data episode.date = form.date.data episode.patient_id = form.patient_id.data episode.hospital_id = form.hospital_id.data episode.surgery_id = form.surgery_id.data episode.comments = form.comments.data episode.created_by = current_user episode.updated_by = current_user db.session.add(episode) db.session.commit() flash('Episode details have been recorded.') return redirect(url_for('episode', id=episode.id)) return render_template('episode.html', title='Record Episode Details', form=form, episode=episode)
def save_episode(origin_name, origin_url): if not origin_name or not origin_url: return episode = Episode.query.filter_by(origin_url=origin_url).first() if episode: return episode serie = None matches = re.search(regex, origin_name) if matches and matches.group('seriename'): serie = save_serie(matches.group('seriename').replace('.', ' ')) season_nr = matches.group('season_nr') if matches else None episode_nr = matches.group('episode_nr') if matches else None episode = Episode(serie=serie, season_nr=season_nr, episode_nr=episode_nr, origin_name=origin_name, origin_url=origin_url) db.session.add(episode) db.session.commit() return episode
def import_episode(): click.echo("Importing Episode...", nl=False) with open("./data/episodes.json") as data_file: episodes = json.load(data_file) for ep in episodes: episode = Episode( id=ep["id"], title=ep["title"], date=parser.parse(ep["date"]), duration=ep["duration"], subtitle=ep["subtitle"], summary=ep["summary"], slug=ep["slug"], youtube=ep["youtube"], time=parser.parse(ep["time"]), ) db.session.add(episode) db.session.commit() click.echo(DONE)
def add_episodes(id): if not request.is_json: return jsonify({'msg': 'Missing or invalid JSON request '}) # Query database for activity to verify existence current_activity = Activity.query.get(id) activity_id = current_activity.id episode_total = request.json.get("episode_total", 0) episode_progress = request.json.get("episode_progress", 0) if activity_id: new_episode = Episode(episode_total=episode_total, episode_progress=episode_progress, activity_id=activity_id) db.session.add(new_episode) db.session.commit() return episode_schema.jsonify(new_episode) else: return jsonify({"msg": "Missing fields"})
def get_episodes(comic_id): try: print("[{0:s}] getting episodes of {1:s}...".format(str(datetime.now()), comic_id)) if '!' in comic_id: # bugfix for 'editordot!' print("[{0:s}] comic_id {1:s} contains illegal character. skip!".format(str(datetime.now()), comic_id)) return None r = None retry_count = RETRY_MAX_COUNT while retry_count > 0: try: r = requests.get(API_URL_EPISODES_FORMAT % (comic_id,), headers=API_HEADER) break except requests.exceptions.ConnectionError as e: print("[{0:s}] connection error. trying again...".format(str(datetime.now()), )) retry_count -= 1 if retry_count <= 0: raise e result = json.loads(r.text) return [Episode(episode_dict) for episode_dict in result] except: import traceback print("[{0:s}] well, an error is coming. (comic_id: {1:s})".format(str(datetime.now()), comic_id)) print(traceback.format_exc())
def get_feed(url, and_subscribe=None): """ - download a RSS url - make a Feed entry for it - populate corresponding Episodes kwargs and_subscribe: if not None, the specified userid gets subscribed to it. """ feedp = feedparser.parse(url) feed = Feed(url, feedp) db.session.add(feed) db.session.flush() for entry in feedp['entries']: title = entry['title'] enclosure = find_enclosure(entry) episode = Episode(feed.id, title, enclosure) db.session.add(episode) if and_subscribe is not None: userid = and_subscribe sub = Subscription(feed.id, userid) db.session.add(sub) db.session.commit()