def index(self): db = Database() genreChart = [] editeurChart = [] genres = db.retrieve(Genre) editeurs = db.retrieve(Editeur) mangas = db.retrieve(Manga) for genre in genres: compteur = 0 for manga in mangas: if manga.genre == genre.genre: for tome in manga.tomes: if tome.possede == True: compteur += 1 if compteur > 0: tuple = (genre.genre, compteur) genreChart.append(tuple) for editeur in editeurs: compteur = 0 for manga in mangas: if manga.editeur == editeur.editeur: for tome in manga.tomes: if tome.possede == True: compteur += 1 if compteur > 0: tuple = (editeur.editeur, compteur) editeurChart.append(tuple) return _index.render_unicode(genres=genreChart, editeurs=editeurChart)
def tome_buy(self, id_manga, id_tome): db = Database() tome = db.retrieveTome(id_manga, id_tome) tome.a_acheter = False tome.possede = True db.update() raise cherrypy.HTTPRedirect('/collection/')
def index(self): db = Database() genreChart = [] editeurChart = [] genres = db.retrieve(Genre) editeurs = db.retrieve(Editeur) mangas = db.retrieve(Manga) for genre in genres: compteur = 0 for manga in mangas: if manga.genre == genre.genre: for tome in manga.tomes: if tome.possede == True: compteur += 1 if compteur > 0: tuple = (genre.genre, compteur) genreChart.append(tuple) for editeur in editeurs: compteur = 0 for manga in mangas: if manga.editeur == editeur.editeur: for tome in manga.tomes: if tome.possede == True: compteur += 1 if compteur >0: tuple = (editeur.editeur, compteur) editeurChart.append(tuple) return _index.render_unicode(genres = genreChart, editeurs = editeurChart)
def manga_add(self, titre, description, editeur, scenariste, dessinateur, statut, genre): manga = Manga(titre, description, editeur, scenariste, dessinateur, statut, genre) db = Database() db.create(manga, Manga) raise cherrypy.HTTPRedirect('/manga/')
def manga_new(self): db = Database() return _manga_new.render_unicode( scenaristes=db.retrieve(Scenariste), dessinateurs=db.retrieve(Dessinateur), editeurs=db.retrieve(Editeur), genres=db.retrieve(Genre) )
def __init__(self, title, body, file_name='', table_name=''): self.title = title self.body = body self.keyword = [ ] # ini adalah keyword yang akan digunakan sebagai link self.table_name = table_name # nama tabel untuk offline support self.conn = Database(file_name)
def search(self, query): db = Database() mangas, editeurs, scenaristes, dessinateurs, genres = db.search(query) return _search.render_unicode(mangas=mangas, editeurs=editeurs, scenaristes=scenaristes, dessinateurs=dessinateurs, genres=genres)
def shopping_list_comfirm(self): db = Database() tomes = db.retrieveTome() for tome in tomes: if tome.a_acheter == True: tome.a_acheter = False tome.possede = True db.update() raise cherrypy.HTTPRedirect('/')
def search(self, query): db = Database() mangas, editeurs, scenaristes, dessinateurs, genres = db.search(query) return _search.render_unicode( mangas=mangas, editeurs=editeurs, scenaristes=scenaristes, dessinateurs=dessinateurs, genres=genres )
def collection(self): db = Database() mangas = db.retrieve(Manga) total = 0 for manga in mangas: for tome in manga.tomes: if tome.possede == True: total += tome.prix total = ceil(total) return _collection.render_unicode(mangas=mangas, total=total)
def anime(id): db = Database(db_name) title = db.read('anime_list', ['judul'], ' WHERE id=' + str(id))[0][0] opinion = db.read('opinion_orientation', ['feature_name', 'good', 'bad'], ' WHERE id_anime=' + str(id)) return render_template('opinion.html', title=title, opinions=opinion)
def collection(self): db = Database() mangas = db.retrieve(Manga) total = 0 for manga in mangas: for tome in manga.tomes: if tome.possede == True: total+= tome.prix total = ceil(total) return _collection.render_unicode(mangas=mangas, total=total)
def shopping_list(self): db = Database() mangas = db.retrieve(Manga) total = 0 for manga in mangas: for tome in manga.tomes: if tome.a_acheter == True: total += tome.prix total = ceil(total) return _shopping_list.render_unicode(mangas=mangas, total=total)
def shopping_list(self): db = Database() mangas = db.retrieve(Manga) total = 0 for manga in mangas: for tome in manga.tomes: if tome.a_acheter == True: total+= tome.prix total = ceil(total) return _shopping_list.render_unicode(mangas = mangas, total=total)
def __run(api, *args): WebApi.checkAuthentication() Database.connect() argCnt = len(args) if argCnt < 1: result = api() elif argCnt == 1: result = api(args[0]) Database.disconnect() bottle.response.content_type = "application/json" return json.dumps(result)
def manga_statut(self, id, statut): db = Database() manga = db.retrieve(Manga, Manga.id, id) print('######################## Statut : ', statut) if statut == 'ongoing': manga.statut = "En cours" if statut == 'complete': manga.statut = "Terminé" if statut == 'pause': manga.statut = "En pause" print('######################## Statut : ', manga.statut) db.update() raise cherrypy.HTTPRedirect('/manga/' + id + '/')
def manga_statut(self, id, statut): db = Database() manga = db.retrieve(Manga, Manga.id, id) print('######################## Statut : ',statut) if statut == 'ongoing': manga.statut = "En cours" if statut == 'complete': manga.statut = "Terminé" if statut == 'pause': manga.statut = "En pause" print('######################## Statut : ', manga.statut) db.update() raise cherrypy.HTTPRedirect('/manga/'+id+'/')
def tome_add(self, manga_id, numero, date_parution, prix, couverture, date_achat=None, possede=None, lu=None, a_acheter=None): tome = Tome(manga_id, numero, date_parution, possede, lu, a_acheter, float(prix), couverture, date_achat) db = Database() db.create(tome, Tome) raise cherrypy.HTTPRedirect('/')
def __init__(self, file_name, id_anime, feature=[]): self.feature_list = set(feature) # Our feature list self.noun_list = [ ] # Our noun list use for transaction and mining the frequent feature self.id_anime = id_anime self.db = Database(file_name) # Our databse interface data = self.db.read(self.table_name, self.column, ' WHERE anime_id=' + id_anime) self.sentences = [] # The review is consist a sentence class # You can look at the sentence class to see what can a sentence do include post tagging, tokenizing and so on for row in data: self.sentences.append(Sentence(row[0].lower(), 5114)) self.feature_result = []
def feed(page): c = Crawler() c.set_url('https://fs.blog/blog/page/' + str(page)) db = Database(db_name) # Ini method untuk mengambil artikel paling paru titles = c.get_feed() # Pengecekan apakah ada artikel yang sudah disimpan # Karena ketika artikel sudah disimpan, maka link akan mengarah ke web seite tersimpan saja title_status = {} for title in titles.keys(): data = db.read('articles', ['id', 'title'], ' WHERE title="' + title + '"') if len(data) > 0: title_status[title] = data[0][0] else: title_status[title] = titles[title] return render_template('feed.html', titles=titles, title_status=title_status, page=page)
def dessinateur_list(self): db = Database() dessinateurs = db.retrieve(Dessinateur) return _dessinateur_list.render_unicode(dessinateurs=dessinateurs)
def editeur_list(self): db = Database() editeurs = db.retrieve(Editeur) return _editeur_list.render_unicode(editeurs=editeurs)
def genre_add(self, genre): db = Database() g = Genre(genre) db.create(g, Genre) raise cherrypy.HTTPRedirect('/genre/')
def tome_read(self, id_manga, id_tome): db = Database() tome = db.retrieveTome(id_manga, id_tome) tome.lu = True db.update() raise cherrypy.HTTPRedirect('/')
def scenariste_add(self, scenariste): db = Database() s = Scenariste(scenariste) db.create(s,Scenariste) raise cherrypy.HTTPRedirect('/scenariste/')
def tome_new(self): db = Database() mangas = db.retrieve(Manga) return _tome_new.render_unicode(mangas = mangas)
def index(): db = Database(db_name) row = db.read('anime_list', ['id', 'judul']) return render_template('index.html', data_title=row)
from datetime import datetime from Core.Database import Database from models import * if __name__ == "__main__": db = Database() #db.loadManga("import") #db.loadTome("importTomes") boucle = True while (boucle): print("Mode console") print("1 - Create") print("2 - Delete") print("3 - Update") print("4 - Quitter") action = int(input("Saisir action ?")) if action == 1: print("Créer un objet") print("1 - Manga") print("2 - Tome") print("3 - Commentaire") action = int(input("Quel objet souhaitez vous créer")) if action == 1: titre = input("Titre ?") description = input("Description ?") editeur = input("Editeur ?") scenariste = input("Scenariste ?") dessinateur = input("Dessinateur ?") statut = input("Statut ?") genre = input("Genre ?")
def article(article_id): db = Database(db_name) data = db.read('articles', ['title', 'raw_article'], ' WHERE id=' + str(article_id)) return render_template('article.html', article=data)
class Article: ''' Class ini akan bertanggung jawab dengan text yang ada dalam artikel ''' def __init__(self, title, body, file_name='', table_name=''): self.title = title self.body = body self.keyword = [ ] # ini adalah keyword yang akan digunakan sebagai link self.table_name = table_name # nama tabel untuk offline support self.conn = Database(file_name) ''' Untuk mengekstrack keyword kita menggunakan rake ''' def extract_keyword(self): # Menggunakan beautiful soup untuk mengambil text dari artikel clean = self.get_clean_body() # Dnegan rake kita ekstract keyword r = Rake(min_length=1, max_length=1) r.extract_keywords_from_text(clean) self.keyword = r.get_ranked_phrases() # Debug di terminal untuk melihat jumlah keyword print('Keyword extracted with ' + str(len(self.keyword)) + ' words') # Menggunakan beautiful soup untuk mengambil teks def get_clean_body(self): return BeautifulSoup(self.body, 'lxml').text ''' Keyword yang ada akan di bandingkand engan judul artikel di wikipedia kemudian akan di beri link ''' def get_wiki(self): key = [] # File bisa didapat di kaggles file = open('titles.txt') for line in file: key.append(line[:-1].lower()) file.close() for i in self.keyword: if i not in key: self.keyword.remove(i) for k in self.keyword: self.body = self.body.replace( ' ' + k + ' ', ' <a href="https://en.wikipedia.org/wiki/' + k + '">' + k + '</a> ') def get_keyword(self): return self.keyword def get_title(self): return self.title def get_content(self): return self.body def clean_html(self): # Drop tag yang menyusahkan dari web td = TagDropper(['img', 'h4', 'svg', 'a', 'figure', 'div', 'path']) td.feed(self.body) self.body = td.get_text() ''' For Database ''' def save_article(self): self.save(['title', 'raw_article'], (self.title, self.body)) self.commit() def save(self, column, data): self.conn.insert(self.table_name, column, data) def commit(self): self.conn.commit()
def index(): db = Database(db_name) row = db.read('articles', ['id', 'title']) return render_template('index.html', data_title=row)
class Review: # First config for read column = ['sentences'] # column table_name = 'sentences' # table name ''' This class provide interface to extract the feature and get the opinion text. This is our main process ''' def __init__(self, file_name, id_anime, feature=[]): self.feature_list = set(feature) # Our feature list self.noun_list = [ ] # Our noun list use for transaction and mining the frequent feature self.id_anime = id_anime self.db = Database(file_name) # Our databse interface data = self.db.read(self.table_name, self.column, ' WHERE anime_id=' + id_anime) self.sentences = [] # The review is consist a sentence class # You can look at the sentence class to see what can a sentence do include post tagging, tokenizing and so on for row in data: self.sentences.append(Sentence(row[0].lower(), 5114)) self.feature_result = [] ''' This method provide an interface to extract the feature list. The process is like this - Use the post tagging to find the noun or a feature candidate. - Save to the noun list - Use assosiation mining to find the frequent feature - Save to the feature list ''' def extract_feature_list(self): if len(self.feature_list) == 0: # Get the noun for each sentences for sentence in self.sentences: for word in sentence.tagged: if word[1] == 'NN': sentence.noun.append(word[0]) # If the sentences didn't countain noun, it's just a dump sentences if len(sentence.noun) > 0: sentence.opinion = True self.noun_list.append(sentence.noun) else: sentence.opinion = False # Use apriori method to mine the feature association_rules = apriori(self.noun_list, min_support=0.001, min_confidence=0, min_lift=3, min_length=2) association_results = list(association_rules) features = [] for item in association_results: pair = item[0] items = [x for x in pair] self.feature_list.add(items[0]) ''' After mine the feature list we mine the opinion about that feature. - First, we get the adjective that most nearby to the noun - We categorize them with positive or negative with wordnet ''' def extract_feature_opinion(self): # List all the feature and make them the key to the dictionary feature_count = {} for feature in self.feature_list: feature_count[feature] = [] # Find all feature and opinion in all sentences for sentence in self.sentences: if sentence.opinion == True: all_words = len(sentence.tagged) for i, j in enumerate(sentence.tagged): # Find the nearby adjective forward or backward if j[1] == 'NN' and j[0] in self.feature_list: count_forward = i count_backward = i while count_forward < all_words and sentence.tagged[ count_forward][1] != 'JJ': count_forward += 1 while count_backward >= 0 and sentence.tagged[ count_backward][1] != 'JJ': count_backward -= 1 count = -1 if count_forward < all_words and count_backward >= 0: if (count_forward - i > i - count_backward): count = count_backward else: count = count_forward if count_backward < 0: count = count_forward if count_forward >= all_words: count = count_backward if count_forward >= all_words and count_backward < 0: count = -1 if count != -1: feature_count[j[0]].append( sentence.tagged[count][0]) # Make the feature class that contain the feature count of positive opinion and negative opinion for i in feature_count.keys(): self.feature_result.append( Feature(self.db, i, feature_count[i], self.id_anime)) # Use wordnet to mine the opinion orientation Feature.OrientationPrediction(Feature.all_adj, Feature.seed) # print(Feature.seed) def get_summary(self): self.extract_feature_list() self.extract_feature_opinion() res = {} for i in self.feature_result: i.save() res[i.feature] = (i.good, i.bad) return res # Save method def save(self): for feature in self.feature_result: feature.save() # Close database def close_db(self): self.db.close()
def test_DeleteInvalidType(self): db = Database("../mangas.sqlite3") self.assertRaises(BadTypeException, db.delete, "blop", Manga) self.assertRaises(BadTypeException, db.delete, 1, Manga) self.assertRaises(BadTypeException, db.delete, None, Manga) self.assertRaises(BadTypeException, db.delete, False, Manga)
def genre_list(self): db = Database() genres = db.retrieve(Genre) return _genre_list.render_unicode(genres=genres)
def __initializeDatabase(self): Database.setName(self.cfg["Database"]["Name"]) if Text.isTrue(self.cfg["Database"]["Rebuild"]): Database.drop() if not Database.exists(): Database.create(True)
def getTranslatorContentFromDatabase(self): return Database.getTranslatorContent(self.getProjectID())
def scenariste_list(self): db = Database() scenaristes = db.retrieve(Scenariste) return _scenariste_list.render_unicode(scenaristes=scenaristes)
def getOutputContentDB(self): return Database.getOutputContent(self.getProjectID())
def tome_detail(self, id_manga, id_tome): db = Database() tome = db.retrieveTome(id_manga,id_tome) return _tome_detail.render_unicode(tome = tome)
def no_category(self): db = Database() mangas = db.retrieve(Manga) return _no_category.render_unicode(mangas = mangas)
def tome_delete(self, id_manga, id_tome): db = Database() tome = db.retrieveTome(id_manga, id_tome) db.deleteTome(tome) raise cherrypy.HTTPRedirect('/')
def manga_list(self): db = Database() mangas = db.retrieve((Manga)) return _manga_list.render_unicode(mangas=mangas)
def tome_cart(self, id_manga, id_tome): db = Database() tome = db.retrieveTome(id_manga, id_tome) tome.a_acheter = True db.update() raise cherrypy.HTTPRedirect('/shopping_list/')
def manga_detail(self, id): db = Database() manga = db.retrieve(Manga, Manga.id, id) commentaire = db.retrieve(Commentaire, Commentaire.id, manga.id) return _manga_detail.render_unicode(manga = manga, commentaire=commentaire)
def tome_add(self, manga_id, numero, date_parution, prix, couverture, date_achat=None, possede=None, lu=None, a_acheter=None): tome = Tome(manga_id, numero, date_parution, possede, lu, a_acheter, float(prix), couverture, date_achat) db = Database() db.create(tome,Tome) raise cherrypy.HTTPRedirect('/')
def manga_delete(self, id): db = Database() manga = db.retrieve(Manga, Manga.id, id) db.delete(manga, Manga) raise cherrypy.HTTPRedirect('/')
def dessinateur_add(self, dessinateur): db = Database() d = Dessinateur(dessinateur) db.create(d, Dessinateur) raise cherrypy.HTTPRedirect('/dessinateur/')
def editeur_add(self, editeur): db = Database() e = Editeur(editeur) db.create(e, Editeur) raise cherrypy.HTTPRedirect('/editeur/')
def getAnalyzerContentDB(self): return Database.getAnalyzerContent(self.getProjectID())
def add_commentaire(self, commentaire, titre, id): db = Database() commentaire = Commentaire(commentaire, titre, id) db.create(commentaire, Commentaire) raise cherrypy.HTTPRedirect('/manga/' + id + '/')
def add_commentaire(self,commentaire, titre, id): db = Database() commentaire = Commentaire(commentaire, titre, id) db.create(commentaire, Commentaire) raise cherrypy.HTTPRedirect('/manga/'+id+'/')
def __exists(projectID): WebApi.checkAuthentication() Database.connect() result = Database.checkProjectExists(projectID) Database.disconnect() return result
def updateDatabase(self): #Database.connect() #projects = Database.getProject("MyProjectID") #print(projects) #Database.disconnect() #sys.exit() if not Text.isTrue(self.cfg["Database"]["Enable"]): Msg.showWarning("Database is NOT enabled in {0}".format( self.cfgPath)) return Database.connect() Database.setDebug(Text.toTrueOrFalse(self.cfg["Database"]["Debug"])) with Database.ORM.db_session: records = Database.Table.Project.get(ID=self.getProjectID()) if records is not None: records.delete() Database.commit() projectTable = Database.Table.Project( ID=self.getProjectID(), Title=Database.sanitize(self.cfg["Title"]), Description=Database.sanitize(self.cfg["Description"]), DateTime=self.frameworkParams["dateTime"], Workflow=self.cfg["Workflow"]) inputTable = Database.Table.Input( ProjectID=projectTable, Content=Database.sanitize( File.getContent(self.frameworkParams["inputPath"])), Source=Database.sanitize( self.cfg["Workflow"]["Input"]["Source"]), PluginName=Database.sanitize( self.cfg["Workflow"]["Input"]["Plugin"]), PluginMethod=Database.sanitize( self.cfg["Workflow"]["Input"]["Method"]), Plugin=self.cfg["Workflow"]["Input"]) analyzerTable = Database.Table.Analyzer( ProjectID=projectTable, Content=Database.sanitize( File.getContent(self.frameworkParams["analyzerPath"])), PluginName=Database.sanitize( self.cfg["Workflow"]["Analyzer"]["Plugin"]), PluginMethod=Database.sanitize( self.cfg["Workflow"]["Analyzer"]["Method"]), Plugin=self.cfg["Workflow"]["Analyzer"]) content = Database.sanitize( File.getContent(self.frameworkParams["translatorPath"])) translatorTable = Database.Table.Translator( ProjectID=projectTable, Content=content, ContentParsed=Result.parseTranslatorContent(content), PluginName=Database.sanitize( self.cfg["Workflow"]["Translator"]["Plugin"]), PluginMethod=Database.sanitize( self.cfg["Workflow"]["Translator"]["Method"]), Plugin=self.cfg["Workflow"]["Translator"]) outputTable = Database.Table.Output( ProjectID=projectTable, Content=Database.sanitize( File.getContent(self.frameworkParams["outputPath"])), Target=Database.sanitize( self.cfg["Workflow"]["Output"]["Target"]), PluginName=Database.sanitize( self.cfg["Workflow"]["Output"]["Plugin"]), PluginMethod=Database.sanitize( self.cfg["Workflow"]["Output"]["Method"]), Plugin=self.cfg["Workflow"]["Output"]) Database.disconnect()
from datetime import datetime from Core.Database import Database from models import * if __name__ == "__main__": db = Database() #db.loadManga("import") #db.loadTome("importTomes") boucle = True while(boucle): print("Mode console") print("1 - Create") print("2 - Delete") print("3 - Update") print("4 - Quitter") action = int(input("Saisir action ?")) if action == 1: print("Créer un objet") print("1 - Manga") print("2 - Tome") print("3 - Commentaire") action = int(input("Quel objet souhaitez vous créer")) if action == 1: titre = input("Titre ?") description = input("Description ?") editeur = input("Editeur ?") scenariste = input("Scenariste ?") dessinateur = input("Dessinateur ?") statut = input("Statut ?") genre = input("Genre ?")