def get_packs_for_anime_group(): dao = DAO(db.session) aid = request.args.get("aid") group_name = request.args.get("group_name") file_packs = dao.get_packs_for_group_anime(aid, group_name) return jsonify(json_list=[e.serialize() for e in file_packs])
def get_anime(anime_key): """ Gets an anime from the db with its sub groups if the anime doesnt have any groups pull the updated group information from anidb and update our db. Then only update the groups for this anime if a certain amoutn of time has passed since it was last updated this is to prevent repeated request to anidb for update information The anime_key is the primary key of a record in our database not the aid """ try: dao = DAO(db.session) anime = dao.get_anime(anime_key) if anime != None: if len(anime.sub_groups) == 0: app.logger.debug("No groups for %s ", anime) app.logger.debug("updating from anidb") # use parser request TODO tomorrows job # reorganise th anidb.py which is an interface to anidb anidb = AniDB() sub_groups_raw = anidb.get_sub_groups(anime) groups = [] for raw in sub_groups_raw: group = Sub_Group(dictionary=raw) groups.append(group) # maye have to add internally without reassignment anime.sub_groups = groups dao.save_anime(anime) db.session.commit() return jsonify(**utils.to_dict(anime)) return ("", 404, []) except: print "somthing went wrotng" db.session.rollback() raise finally: db.session.close() return ("", 400, [])
def search_animes(): """ Search the databse for animes with the url /api/search/animes?search_term=somthig... """ param_key = "search_term" search_term = request.args[param_key] dao = DAO(db.session) try: result = dao.search_anime(search_term) if len(result) == 0: return ("", 404, []) else: # this will need fixing app.logger.debug("found %s", len(result)) return jsonify(json_list=[e.serialize() for e in result]) except Exception as e: app.logger.exception(e) return (str(e), 500, []) finally: db.session.close() anime = Anime("one", "two", "three", "four") return jsonify(**utils.to_dict(anime))
def titles_upload(): data = request.data poo = json.loads(data) print len(poo) dao = DAO(db.session) animes = [] # parse json for i in poo: try: anime = Anime(dictionary=i) animes.append(anime) except Exception as e: pass print "Doing db" # do db update print str(len(animes)) try: if len(animes) != 0: result = dao.update_animes(animes) print result print "done dao" db.session.commit() return ("inserted " + str(result[0]) + " updated " + str(result[1]), 200, []) except Exception as e: print e print "failed to update animes rolling back ..." db.session.rollback() return (str(e), 500, []) finally: db.session.close() return ("Your data is empty", 400, [])