本文整理汇总了Python中DatabaseHandler.addRequest方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseHandler.addRequest方法的具体用法?Python DatabaseHandler.addRequest怎么用?Python DatabaseHandler.addRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseHandler
的用法示例。
在下文中一共展示了DatabaseHandler.addRequest方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buildMangaReplyWithAuthor
# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addRequest [as 别名]
def buildMangaReplyWithAuthor(searchText, authorName, message, isExpanded, blockTracking=False):
try:
ani = Anilist.getMangaWithAuthor(searchText, authorName)
mal = None
mu = None
ap = None
if ani:
mal = MAL.getMangaCloseToDescription(searchText, ani['description'])
ap = AniP.getMangaURL(ani['title_english'], authorName)
else:
ap = AniP.getMangaURL(searchText, authorName)
mu = MU.getMangaWithAuthor(searchText, authorName)
if ani:
try:
titleToAdd = ''
if mal is not None:
titleToAdd = mal['title']
else:
titleToAdd = ani['title_english']
if not blockTracking:
DatabaseHandler.addRequest(titleToAdd, 'Manga', message.author.id, message.server.id)
except:
traceback.print_exc()
pass
return CommentBuilder.buildMangaComment(isExpanded, mal, ani, mu, ap)
except Exception as e:
traceback.print_exc()
return None
示例2: buildMangaReplyWithAuthor
# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addRequest [as 别名]
def buildMangaReplyWithAuthor(searchText, authorName, isExpanded, baseComment, blockTracking=False):
try:
ani = Anilist.getMangaWithAuthor(searchText, authorName)
mal = None
mu = None
ap = None
if ani:
mal = MAL.getMangaCloseToDescription(searchText, ani['description'])
ap = AniP.getMangaURL(ani['title_english'], authorName)
else:
ap = AniP.getMangaURL(searchText, authorName)
mu = MU.getMangaWithAuthor(searchText, authorName)
if ani:
try:
titleToAdd = ''
if mal is not None:
titleToAdd = mal['title']
else:
titleToAdd = ani['title_english']
if (str(baseComment.subreddit).lower is not 'nihilate') and (str(baseComment.subreddit).lower is not 'roboragi') and not blockTracking:
DatabaseHandler.addRequest(titleToAdd, 'Manga', baseComment.author.name, baseComment.subreddit)
except:
traceback.print_exc()
pass
return CommentBuilder.buildMangaComment(isExpanded, mal, ani, mu, ap)
except Exception as e:
traceback.print_exc()
return None
示例3: run
# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addRequest [as 别名]
def run(self):
try:
print("Starting stream")
commentStream = praw.helpers.comment_stream(self.reddit, self.subredditList, limit=1000, verbosity=0)
for comment in commentStream:
if ((time.time() - self.updateTime) > Config.tcgUpdateInterval * 60 * 60):
DatabaseHandler.updateTCGCardlist()
self.updateTime = time.time()
if ((time.time() - self.submissionsLastProcessed) > Config.submissionProcessingInterval * 60 * 60):
self.submissionProcessor.processSubmissions(100)
self.submissionsLastProcessed = time.time()
#print("Found comment")
#If we've already seen this comment, ignore it
if DatabaseHandler.commentExists(comment.id):
continue
#If the post has been deleted, getting the author will return an error
try:
author = comment.author.name
except Exception as e:
continue
#If this is one of our own comments, ignore it
if (author == 'YugiohLinkBot'):
continue
reply = self.requestHandler.buildResponse(comment.body)
try:
if reply:
cards = re.findall('\[\*\*(.+?)\*\*\]\(', reply)
for card in cards:
DatabaseHandler.addRequest(card, author, comment.subreddit)
if("VENT THREAD" in comment.link_title):
reply = self.submissionProcessor.convertCase(True, reply)
elif("happiness thread" in comment.link_title):
reply = self.submissionProcessor.convertCase(False, reply)
DatabaseHandler.addComment(comment.id, author, comment.subreddit, True)
comment.reply(reply)
print("Comment made.\n")
else:
if ('{' in comment.body and '}' in comment.body):
print('')
DatabaseHandler.addComment(comment.id, author, comment.subreddit, False)
except Exception as e:
print("Reddit probably broke when replying:" + str(e) + '\n')
except Exception as e:
print("Error with comment stream: " + str(e))
traceback.print_exc()
示例4: buildMangaReply
# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addRequest [as 别名]
def buildMangaReply(searchText, isExpanded, baseComment):
try:
#Basic breakdown:
#If Anilist finds something, use it to find the MAL version.
#If hits either MAL or Ani, use it to find the MU version.
#If it hits either, add it to the request-tracking DB.
ani = Anilist.getMangaDetails(searchText)
mal = None
mu = None
if not (ani is None):
mal = MAL.getMangaDetails(ani['title_romaji'])
else:
mal = MAL.getMangaDetails(searchText)
if not (mal is None):
ani = Anilist.getMangaDetails(mal['title'])
if (ani is not None) or (mal is not None):
try:
titleToAdd = ''
if mal is not None:
titleToAdd = mal['title']
mu = MU.getMangaURL(mal['title'])
else:
titleToAdd = ani['title_english']
mu = MU.getMangaURL(ani['title_romaji'])
if (str(baseComment.subreddit).lower is not 'nihilate') and (str(baseComment.subreddit).lower is not 'roboragi'):
DatabaseHandler.addRequest(titleToAdd, 'Manga', baseComment.author.name, baseComment.subreddit)
except:
traceback.print_exc()
pass
if ani is not None:
if ani['adult'] is True:
print("NSFW ENTRY")
mal = None
ani = None
mu = None
return CommentBuilder.buildMangaComment(isExpanded, mal, ani, mu)
except Exception as e:
traceback.print_exc()
return None
示例5: processSubmissions
# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addRequest [as 别名]
def processSubmissions(self, num):
subreddits = self.reddit.get_subreddit(self.subredditList)
for submission in subreddits.get_new(limit=num):
#If we've already seen this submission, ignore it
if DatabaseHandler.commentExists(submission.id):
continue
#If the post has been deleted, getting the author will return an error
try:
author = submission.author.name
except Exception as e:
continue
#If this is one of our own submissions, ignore it
if (author == 'YugiohLinkBot'):
continue
reply = self.requestHandler.buildResponse(submission.selftext)
try:
if reply:
cards = re.findall('\[\*\*(.+?)\*\*\]\(', reply)
for card in cards:
DatabaseHandler.addRequest(card, author, submission.subreddit)
if("VENT THREAD" in submission.title):
reply = self.convertCase(True, reply)
elif("happiness thread" in submission.title):
reply = self.convertCase(False, reply)
DatabaseHandler.addComment(submission.id, author, submission.subreddit, True)
submission.add_comment(reply)
print("Comment made.\n")
else:
if ('{' in submission.selftext and '}' in submission.selftext):
print('')
DatabaseHandler.addComment(submission.id, author, submission.subreddit, False)
except Exception as e:
traceback.print_exc()
print("Reddit probably broke when replying:" + str(e) + '\n')
示例6: buildMangaReply
# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addRequest [as 别名]
def buildMangaReply(searchText, isExpanded, baseComment, blockTracking=False):
try:
ani = None
mal = None
mu = None
ap = None
try:
sqlCur.execute('SELECT dbLinks FROM synonyms WHERE type = "Manga" and lower(name) = ?', [searchText.lower()])
except sqlite3.Error as e:
print(e)
alternateLinks = sqlCur.fetchone()
if (alternateLinks):
synonym = json.loads(alternateLinks[0])
if (synonym['mal']):
mal = MAL.getMangaDetails(synonym['mal'])
if (synonym['ani']):
ani = Anilist.getMangaDetails(synonym['ani'])
if (synonym['mu']):
mu = MU.getMangaURL(synonym['mu'])
if (synonym['ap']):
ap = AniP.getMangaURL(synonym['ap'])
else:
#Basic breakdown:
#If Anilist finds something, use it to find the MAL version.
#If hits either MAL or Ani, use it to find the MU version.
#If it hits either, add it to the request-tracking DB.
ani = Anilist.getMangaDetails(searchText)
if not (ani is None):
mal = MAL.getMangaDetails(ani['title_romaji'])
else:
mal = MAL.getMangaDetails(searchText)
if not (mal is None):
ani = Anilist.getMangaDetails(mal['title'])
#----- Finally... -----#
if ani or mal:
try:
titleToAdd = ''
if mal:
titleToAdd = mal['title']
else:
titleToAdd = ani['title_english']
if not alternateLinks:
#MU stuff
if mal:
mu = MU.getMangaURL(mal['title'])
else:
mu = MU.getMangaURL(ani['title_romaji'])
#Do the anime-planet stuff
if mal and not ap:
if mal['title'] and not ap:
ap = AniP.getMangaURL(mal['title'])
if mal['english'] and not ap:
ap = AniP.getMangaURL(mal['english'])
if mal['synonyms'] and not ap:
for synonym in mal['synonyms']:
if ap:
break
ap = AniP.getMangaURL(synonym)
if ani and not ap:
if ani['title_english'] and not ap:
ap = AniP.getMangaURL(ani['title_english'])
if ani['title_romaji'] and not ap:
ap = AniP.getMangaURL(ani['title_romaji'])
if ani['synonyms'] and not ap:
for synonym in ani['synonyms']:
if ap:
break
ap = AniP.getMangaURL(synonym)
if (str(baseComment.subreddit).lower is not 'nihilate') and (str(baseComment.subreddit).lower is not 'roboragi') and not blockTracking:
DatabaseHandler.addRequest(titleToAdd, 'Manga', baseComment.author.name, baseComment.subreddit)
except:
traceback.print_exc()
pass
if ani is not None:
if ani['adult'] is True:
mal = None
ani = None
mu = None
ap = None
return CommentBuilder.buildMangaComment(isExpanded, mal, ani, mu, ap)
except Exception as e:
traceback.print_exc()
return None
示例7: buildAnimeReply
# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addRequest [as 别名]
#.........这里部分代码省略.........
if not mal:
if hb:
mal = MAL.getAnimeDetails(hb['title'])
if not mal and hb['alternate_title']:
if (hb['alternate_title']):
mal = MAL.getAnimeDetails(hb['alternate_title'])
if ani and not mal:
mal = MAL.getAnimeDetails(ani['title_romaji'])
if not mal:
mal = MAL.getAnimeDetails(ani['title_english'])
if not mal and ani['synonyms']:
for synonym in ani['synonyms']:
if mal:
break
mal = MAL.getAnimeDetails(synonym)
if not mal:
mal = MAL.getAnimeDetails(searchText)
if mal and not hb:
hb = Hummingbird.getAnimeDetails(mal['title'])
if not hb:
hb = Hummingbird.getAnimeDetails(mal['english'])
if mal and not ani:
ani = Anilist.getAnimeDetails(mal['title'])
if not ani:
ani = Anilist.getAnimeDetails(mal['english'])
#----- Finally... -----#
try:
if ani is not None:
aniFull = Anilist.getFullAnimeDetails(ani['id'])
if aniFull is not None:
ani = aniFull
except:
pass
if (ani is not None) or (hb is not None) or (mal is not None):
try:
titleToAdd = ''
if mal:
titleToAdd = mal['title']
if hb:
titleToAdd = hb['title']
if ani:
titleToAdd = ani['title_romaji']
#Do Anime-Planet stuff
if mal and not ap:
if mal['title'] and not ap:
ap = AniP.getAnimeURL(mal['title'])
if mal['english'] and not ap:
ap = AniP.getAnimeURL(mal['english'])
if mal['synonyms'] and not ap:
for synonym in mal['synonyms']:
if ap:
break
ap = AniP.getAnimeURL(synonym)
if hb and not ap:
if hb['title'] and not ap:
ap = AniP.getAnimeURL(hb['title'])
if hb['alternate_title'] and not ap:
ap = AniP.getAnimeURL(hb['alternate_title'])
if ani and not ap:
if ani['title_english'] and not ap:
ap = AniP.getAnimeURL(ani['title_english'])
if ani['title_romaji'] and not ap:
ap = AniP.getAnimeURL(ani['title_romaji'])
if ani['synonyms'] and not ap:
for synonym in ani['synonyms']:
if ap:
break
ap = AniP.getAnimeURL(synonym)
if (str(baseComment.subreddit).lower is not 'nihilate') and (str(baseComment.subreddit).lower is not 'roboragi') and not blockTracking:
DatabaseHandler.addRequest(titleToAdd, 'Anime', baseComment.author.name, baseComment.subreddit)
except:
traceback.print_exc()
pass
if ani is not None:
if ani['adult'] is True:
print("NSFW ENTRY")
mal = None
hb = None
ani = None
ap = None
return CommentBuilder.buildAnimeComment(isExpanded, mal, hb, ani, ap)
except Exception as e:
traceback.print_exc()
return None
示例8: buildAnimeReply
# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addRequest [as 别名]
def buildAnimeReply(searchText, isExpanded, baseComment, blockTracking=False):
try:
mal = {'search_function': MAL.getAnimeDetails,
'synonym_function': MAL.getSynonyms,
'checked_synonyms': [],
'result': None}
hb = {'search_function': Hummingbird.getAnimeDetails,
'synonym_function': Hummingbird.getSynonyms,
'checked_synonyms': [],
'result': None}
ani = {'search_function': Anilist.getAnimeDetails,
'synonym_function': Anilist.getSynonyms,
'checked_synonyms': [],
'result': None}
ap = {'search_function': AniP.getAnimeURL,
'result': None}
adb = {'search_function': AniDB.getAnimeURL,
'result': None}
try:
sqlCur.execute('SELECT dbLinks FROM synonyms WHERE type = "Anime" and lower(name) = ?', [searchText.lower()])
except sqlite3.Error as e:
print(e)
alternateLinks = sqlCur.fetchone()
if (alternateLinks):
synonym = json.loads(alternateLinks[0])
if synonym:
malsyn = None
if 'mal' in synonym and synonym['mal']:
malsyn = synonym['mal']
hbsyn = None
if 'hb' in synonym and synonym['hb']:
hbsyn = synonym['hb']
anisyn = None
if 'ani' in synonym and synonym['ani']:
anisyn = synonym['ani']
apsyn = None
if 'ap' in synonym and synonym['ap']:
apsyn = synonym['ap']
adbsyn = None
if 'adb' in synonym and synonym['adb']:
adbsyn = synonym['adb']
mal['result'] = MAL.getAnimeDetails(malsyn[0],malsyn[1]) if malsyn else None
hb['result'] = Hummingbird.getAnimeDetailsById(hbsyn) if hbsyn else None
ani['result'] = Anilist.getAnimeDetailsById(anisyn) if anisyn else None
ap['result'] = AniP.getAnimeURLById(apsyn) if apsyn else None
adb['result'] = AniDB.getAnimeURLById(adbsyn) if adbsyn else None
else:
data_sources = [ani, hb, mal]
aux_sources = [ap, adb]
synonyms = set([searchText])
for x in range(len(data_sources)):
for source in data_sources:
if source['result']:
break
else:
for synonym in synonyms:
if synonym in source['checked_synonyms']:
continue
source['result'] = source['search_function'](synonym)
source['checked_synonyms'].append(synonym)
if source['result']:
break
if source['result']:
synonyms.update([synonym.lower() for synonym in source['synonym_function'](source['result'])])
for source in aux_sources:
for synonym in synonyms:
source['result'] = source['search_function'](synonym)
if source['result']:
break
if ani['result'] or hb['result'] or mal['result']:
try:
titleToAdd = ''
if mal['result']:
titleToAdd = mal['result']['title']
if hb['result']:
titleToAdd = hb['result']['title']
if ani['result']:
titleToAdd = ani['result']['title_romaji']
if (str(baseComment.subreddit).lower is not 'nihilate') and (str(baseComment.subreddit).lower is not 'roboragi') and not blockTracking:
DatabaseHandler.addRequest(titleToAdd, 'Anime', baseComment.author.name, baseComment.subreddit)
#.........这里部分代码省略.........
示例9: buildLightNovelReply
# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addRequest [as 别名]
def buildLightNovelReply(searchText, isExpanded, baseComment, blockTracking=False):
try:
mal = {'search_function': MAL.getLightNovelDetails,
'synonym_function': MAL.getSynonyms,
'checked_synonyms': [],
'result': None}
ani = {'search_function': Anilist.getLightNovelDetails,
'synonym_function': Anilist.getSynonyms,
'checked_synonyms': [],
'result': None}
nu = {'search_function': NU.getLightNovelURL,
'result': None}
lndb = {'search_function': LNDB.getLightNovelURL,
'result': None}
try:
sqlCur.execute('SELECT dbLinks FROM synonyms WHERE type = "LN" and lower(name) = ?', [searchText.lower()])
except sqlite3.Error as e:
print(e)
alternateLinks = sqlCur.fetchone()
if (alternateLinks):
synonym = json.loads(alternateLinks[0])
if synonym:
malsyn = None
if 'mal' in synonym and synonym['mal']:
malsyn = synonym['mal']
anisyn = None
if 'ani' in synonym and synonym['ani']:
anisyn = synonym['ani']
nusyn = None
if 'nu' in synonym and synonym['nu']:
nusyn = synonym['nu']
lndbsyn = None
if 'lndb' in synonym and synonym['lndb']:
lndbsyn = synonym['lndb']
mal['result'] = MAL.getLightNovelDetails(malsyn[0],malsyn[1]) if malsyn else None
ani['result'] = Anilist.getMangaDetailsById(anisyn) if anisyn else None
nu['result'] = NU.getLightNovelById(nusyn) if nusyn else None
lndb['result'] = LNDB.getLightNovelById(lndbsyn) if lndbsyn else None
else:
data_sources = [ani, mal]
aux_sources = [nu, lndb]
synonyms = set([searchText])
for x in range(len(data_sources)):
for source in data_sources:
if source['result']:
break
else:
for synonym in synonyms:
if synonym in source['checked_synonyms']:
continue
source['result'] = source['search_function'](synonym)
source['checked_synonyms'].append(synonym)
if source['result']:
break
if source['result']:
synonyms.update([synonym.lower() for synonym in source['synonym_function'](source['result'])])
for source in aux_sources:
for synonym in synonyms:
source['result'] = source['search_function'](synonym)
if source['result']:
break
if ani['result'] or mal['result']:
try:
titleToAdd = ''
if mal['result']:
titleToAdd = mal['result']['title']
if ani['result']:
try:
titleToAdd = ani['result']['title_romaji']
except:
titleToAdd = ani['result']['title_english']
if (str(baseComment.subreddit).lower is not 'nihilate') and (str(baseComment.subreddit).lower is not 'roboragi') and not blockTracking:
DatabaseHandler.addRequest(titleToAdd, 'LN', baseComment.author.name, baseComment.subreddit)
except:
traceback.print_exc()
pass
return CommentBuilder.buildLightNovelComment(isExpanded, mal['result'], ani['result'], nu['result'], lndb['result'])
except Exception as e:
traceback.print_exc()
return None
示例10: buildAnimeReply
# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addRequest [as 别名]
def buildAnimeReply(searchText, isExpanded, baseComment):
try:
#Basic breakdown:
#If Anilist finds something, use it to find the HB version.
#If we can't find it, try with HB and use it to try and "refind" Anilist
#If we hit HB, we don't need to look for MAL, since we can get the MAL ID from within HB. If we don't hit HB, find MAL on its own.
#If, at the end, we have something from Anilist, get the full set of Anilist data
#If it hits anything, add it to the request-tracking DB.
ani = Anilist.getAnimeDetails(searchText)
hb = None
mal = None
if (ani is not None):
hb = Hummingbird.getAnimeDetails(ani['title_romaji'])
if (hb is None):
for synonym in ani['synonyms']:
hb = Hummingbird.getAnimeDetails(synonym)
if hb is not None:
break
hb = Hummingbird.getAnimeDetails(ani['title_english'])
else:
hb = Hummingbird.getAnimeDetails(searchText)
if (hb is not None):
ani = Anilist.getAnimeDetails(hb['title'])
if (hb is None):
mal = MAL.getAnimeDetails(searchText)
if (mal is not None):
hb = Hummingbird.getAnimeDetails(mal['title'])
if (hb is None):
hb = Hummingbird.getAnimeDetails(mal['english'])
if (ani is None):
ani = Anilist.getAnimeDetails(mal['title'])
if (ani is None):
ani = Anilist.getAnimeDetails(mal['english'])
try:
if ani is not None:
aniFull = Anilist.getFullAnimeDetails(ani['id'])
if aniFull is not None:
ani = aniFull
except:
pass
if (ani is not None) or (hb is not None) or (mal is not None):
try:
titleToAdd = ''
if ani is None:
titleToAdd = hb['title']
elif hb is not None:
titleToAdd = ani['title_romaji']
else:
titleToAdd = mal['title']
if (str(baseComment.subreddit).lower is not 'nihilate') and (str(baseComment.subreddit).lower is not 'roboragi'):
DatabaseHandler.addRequest(titleToAdd, 'Anime', baseComment.author.name, baseComment.subreddit)
except:
traceback.print_exc()
pass
if ani is not None:
if ani['adult'] is True:
print("NSFW ENTRY")
mal = None
hb = None
ani = None
return CommentBuilder.buildAnimeComment(isExpanded, mal, hb, ani)
except Exception as e:
traceback.print_exc()
return None