def manga_list(): ''' print manga list ''' mangas = store.find(Manga) for manga in mangas.order_by(Manga.name): chapters = store.find(Chapter, Chapter.id_manga == manga.id) print '%s (id:%s)\t\t\t - scaricati: %s'\ % (manga.name, manga.id, chapters.count())
def manga_list_missed_manga(): ''' manga con 0 capitoli scaricati ''' mangas = store.find(Manga) for manga in mangas.order_by(Manga.name): chapters = store.find(Chapter, Chapter.id_manga == manga.id) if chapters.count() == 0: print '%s (id:%s)' % (manga.name, manga.id)
def cerca(): ''' search record ''' manga_id = int(raw_input('ID manga: ')) manga = store.find(Manga, Manga.id == manga_id).one() chapters = store.find(Chapter, Chapter.id_manga == manga_id) print '%s - %s' % (manga.name, manga.data) for chapter in chapters: print '' print '%s - %s' % (chapter.link, chapter.data)
def status_zero(): ''' ''' print "\n\nList chapters still to download!\n" chapters = store.find(Chapter, Chapter.status == 0) for chapter in chapters.order_by(Chapter.id): print "%s - %s" % (chapter.id, chapter.link)
def manga_list_download_history(): from datetime import timedelta, datetime, date now = datetime.now() today = date.today() mangas = store.find(Manga, Manga.data < now ) for manga in mangas.order_by(Manga.data): print "%s %s -> %s" % (manga.name, manga.data.date(), (today - manga.data.date()).days )
def send_mail(body): import smtplib rows = store.find(Mail) for row in rows: body2 = "From: %s\n" % (row.from_addr) body2 += "To: %s\n" % (row.to_addr) body2 += "Subject: %s\n\n" % (row.subject,) body2 += body server = smtplib.SMTP(row.smtp) server.sendmail(row.from_addr, [row.to_addr], body2) server.quit()
def delete_manga(): ''' remove event ''' record_id = int(raw_input('ID to been removed: ')) record = store.find(Manga, Manga.id == record_id) if not record.count(): print 'nothing to remove' return for i in record.order_by(Manga.id): print "%s - %s - status; %s" % (i.id, i.name,\ i.status) conferma = raw_input("(q to abort): ") if conferma == "q": print 'aborted' return store.remove(record[0]) store.commit() print 'record removed' return
def delete_chapter(): ''' remove event ''' record_id = int(raw_input('ID to been removed: ')) record = store.find(Chapter, Chapter.id == record_id) if not record.count(): print 'nothing to remove' return for i in record.order_by(Chapter.id): print "%s - %s - status; %s" % (i.id, i.link,\ i.status) conferma = raw_input("(q to abort): ") if conferma == "q": print 'aborted' return print 'record removed' store.remove(record[0]) store.commit() return
#!/usr/bin/env python ''' inserire i vecchi valori di config.cfg nel database config.cfg --> database ''' from mangadb import store, Manga, Mail if __name__ == "__main__": #verifichiamo print '\nVerifica inserimento dati email nel db\n' rows = store.find(Mail) for row in rows: print row.id print 'from: %s\nto: %s\nsubject: %s\nsmtp: %s\n'\ % (row.from_addr, row.to_addr, row.subject, row.smtp) print '\nVerifica inserimento manga nel db\n' rows = store.find(Manga) for row in rows: print 'Manga: %s' % (row.name)
def main(): body = '' # fetch new links from website x = mangareader('http://www.mangareader.net/latest') for manga in store.find(Manga): name = x.convert_name(manga.name) links = x.fetch_chapters_manga(name) if links: for link, number in links: if not store.find(Chapter.link, Chapter.link == unicode(link)).count(): new_chapter = store.add(Chapter()) new_chapter.link = unicode(link) new_chapter.status = 0 new_chapter.id_manga = manga.id store.add(new_chapter) store.commit() store.flush() # download links with status 0 rows = store.find(Chapter, Chapter.status == 0) if rows.count(): stampa('Da Scaricare:') for row in rows: stampa(' %s' % row.link) for row in rows: # re-check status, just in case.. this_chap = store.find(Chapter, Chapter.id == row.id) if this_chap[0].status == 2: stampa('Status cambiato per %s' % row.link) continue row.status = 2 row.data = now() store.commit() store.flush() ## stampa('\nScarico %s' % row.link) if download_chapter(row.link): row.status = 1 row.data = now() row.manga.data = now() store.commit() store.flush() body += '\nScaricato %s:\n' % (row.link) else: body += '\nErrore nello scaricare %s:\n' % (row.link) # report links with status 0 rows = store.find(Chapter, Chapter.status == 0) if rows.count(): body += '\n\n###Da scaricare' for row in rows: body += '\nDa scaricare %s:\n' % (row.link) # report links with status 2 rows = store.find(Chapter, Chapter.status == 2) if rows.count(): body += '\n\n###Chapter in via di scaricamento' for row in rows: body += '\n --> %s:\n' % (row.link) if body: send_mail(body)