本文整理汇总了Python中pynab.log.info函数的典型用法代码示例。如果您正苦于以下问题:Python info函数的具体用法?Python info怎么用?Python info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了info函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: search
def search(name, year):
"""Search OMDB for a movie and return the IMDB ID."""
log.info('Searching for movie: {}'.format(name))
# if we managed to parse the year from the name
# include it, since it'll narrow results
if year:
year_query = '&y={}'.format(year.replace('(', '').replace(')', ''))
else:
year_query = ''
r = requests.get(OMDB_SEARCH_URL + name + year_query)
try:
data = r.json()
except:
log.debug('There was a problem accessing the API page.')
return None
if 'Search' in data:
for movie in data['Search']:
# doublecheck, but the api should've searched properly
ratio = difflib.SequenceMatcher(None, clean_name(name), clean_name(movie['Title'])).ratio()
if ratio > 0.8 and year == movie['Year'] and movie['Type'] == 'movie':
log.info('OMDB movie match found: {}'.format(movie['Title']))
return movie
示例2: get
def get(self, group_name, messages=None):
"""Get a set of messages from the server for the specified group."""
log.info('{}: Getting {:d} messages...'.format(group_name, len(messages)))
data = ''
if messages:
try:
_, total, first, last, _ = self.connection.group(group_name)
log.debug('{}: Total articles in group: {:d}'.format(group_name, total))
for message in messages:
article = '<{}>'.format(message)
log.debug('{}: Getting article: {}'.format(group_name, article))
response, (number, message_id, lines) = self.connection.body(article)
res = pynab.yenc.yenc_decode(lines)
if res:
data += res
else:
return None
except nntplib.NNTPError as nntpe:
log.error('{}: Problem retrieving messages from server: {}.'.format(group_name, nntpe))
return None
return data
else:
log.error('{}: No messages were specified.'.format(group_name))
return None
示例3: rename_bad_releases
def rename_bad_releases(category):
for release in db.releases.find(
{"category._id": int(category), "$or": [{"nfo": {"$nin": [None, False]}}, {"files.count": {"$exists": True}}]}
):
log.debug("Finding name for {}...".format(release["search_name"]))
name, category_id = pynab.releases.discover_name(release)
if name and not category_id:
# don't change anything, it was fine
pass
elif name and category_id:
# we found a new name!
log.info(
"Renaming {} ({:d}) to {} ({:d})...".format(
release["search_name"], release["category"]["_id"], name, category_id
)
)
category = db.categories.find_one({"_id": category_id})
category["parent"] = db.categories.find_one({"_id": category["parent_id"]})
db.releases.update(
{"_id": release["_id"]},
{"$set": {"search_name": pynab.releases.clean_release_name(name), "category": category}},
)
else:
# bad release!
log.debug("Noting unwanted release {} ({:d})...".format(release["search_name"], release["category"]["_id"]))
db.releases.update({"_id": release["_id"]}, {"$set": {"unwanted": True}})
示例4: determine_category
def determine_category(name, group_name=''):
"""Categorise release based on release name and group name."""
category = ''
if is_hashed(name):
category = CAT_MISC_OTHER
else:
if group_name:
category = check_group_category(name, group_name)
if not category:
for parent_category in parent_category_regex.keys():
category = check_parent_category(name, parent_category)
if category:
break
if not category:
category = CAT_MISC_OTHER
log.info('category: ({}) [{}]: {} ({})'.format(
group_name,
name,
get_category_name(category),
category
))
return category
示例5: process
def process(limit=20, category=0):
"""Processes release rarfiles to check for passwords and filecounts."""
with Server() as server:
query = {"passworded": None}
if category:
query["category._id"] = int(category)
for release in db.releases.find(query).limit(limit).sort("posted", pymongo.DESCENDING).batch_size(50):
nzb = pynab.nzbs.get_nzb_dict(release["nzb"])
if nzb and "rars" in nzb:
info = check_release_files(server, release["group"]["name"], nzb)
if info:
log.info("[{}] - [{}] - file info: added".format(release["_id"], release["search_name"]))
db.releases.update(
{"_id": release["_id"]},
{
"$set": {
"files.count": info["files.count"],
"files.size": info["files.size"],
"files.names": info["files.names"],
"passworded": info["passworded"],
}
},
)
continue
log.warning(
"rar: [{}] - [{}] - file info: no rars in release".format(release["_id"], release["search_name"])
)
db.releases.update(
{"_id": release["_id"]},
{"$set": {"files.count": 0, "files.size": 0, "files.names": [], "passworded": "unknown"}},
)
示例6: update_blacklist
def update_blacklist():
"""Check for Blacklist update and load them into Mongo."""
if 'blacklist_url' in config.site:
log.info('Starting blacklist update...')
response = requests.get(config.site['blacklist_url'])
lines = response.text.splitlines()
for line in lines:
elements = line.split('\t\t')
if len(elements) == 4:
log.debug('Updating blacklist {}...'.format(elements[1]))
db.blacklists.update(
{
'regex': elements[1]
},
{
'$setOnInsert': {
'status': 0
},
'$set': {
'group_name': elements[0],
'regex': elements[1],
'description': elements[3],
}
},
upsert=True
)
return True
else:
log.error('No blacklist update url in config.')
return False
示例7: start
def start(self):
log.info("nabbot: xmpp bot started")
if self.xmpp.connect():
self.xmpp.process(block=False) # pynab.xmpp is started in its own thread
# self.create_nodes() #I have autocreate set, don't need to pre-populate
self.handle_queue()
else:
log.error("nabbot: client didn't connect.")
示例8: process
def process():
# process binaries
log.info('scan: processing binaries...')
pynab.binaries.process()
# process releases
log.info('scan: processing releases...')
pynab.releases.process()
示例9: publish
def publish(self, guid, name, catid):
categories = self.get_categories()
data = "<name>{}</name><guid>{}</guid>".format(escape(name), guid)
log.info("nabbot: publishing {} to {}[{}] at {}".format(data, categories[catid], catid, datetime.now()))
try:
self.xmpp.publish(str(catid), data)
pass
except:
pass
示例10: main
def main():
channel = config.prebot.get("channel")
nick = config.prebot.get("nick")
server = config.prebot.get("server")
port = config.prebot.get("port")
log.info("Pre: Bot Nick - {}".format(nick))
bot = TestBot(channel, nick, server, port)
bot.start()
示例11: get_details
def get_details(id):
log.info("Retrieving movie details for {}...".format(id))
r = requests.get(OMDB_DETAIL_URL + id)
data = r.json()
if "Response" in data:
imdb = {"_id": data["imdbID"], "title": data["Title"], "year": data["Year"], "genre": data["Genre"].split(",")}
return imdb
else:
return None
示例12: process
def process(limit=None, category=0):
"""Processes release rarfiles to check for passwords and filecounts."""
with Server() as server:
with db_session() as db:
# noinspection PyComparisonWithNone
query = db.query(Release).join(Group).join(NZB).filter(~Release.files.any()). \
filter(Release.passworded == 'UNKNOWN').filter(Release.rar_metablack_id == None)
if category:
query = query.filter(Release.category_id == int(category))
if limit:
releases = query.order_by(Release.posted.desc()).limit(limit)
else:
releases = query.order_by(Release.posted.desc()).all()
for release in releases:
log.debug('rar: processing {}'.format(release.search_name))
nzb = pynab.nzbs.get_nzb_details(release.nzb)
if nzb and nzb['rars']:
try:
passworded, info = check_release_files(server, release.group.name, nzb)
except Exception as e:
# if usenet isn't accessible, we don't want to blacklist it
log.error('rar: file info failed: {}'.format(e))
continue
if info:
log.info('rar: file info add [{}]'.format(
release.search_name
))
release.passworded = passworded
size = 0
for file in info:
f = File(name=file['name'][:512],
size=file['size'])
f.release = release
size += file['size']
db.add(f)
if size != 0:
release.size = size
release.rar_metablack_id = None
db.add(release)
db.commit()
continue
log.debug('rar: [{}] - file info: no readable rars in release'.format(
release.search_name
))
mb = MetaBlack(rar=release, status='IMPOSSIBLE')
db.add(mb)
db.commit()
示例13: process
def process(limit=None, category=0):
"""Process releases for SFV parts and download them."""
with Server() as server:
with db_session() as db:
# noinspection PyComparisonWithNone,PyComparisonWithNone
query = db.query(Release).join(Group).join(NZB).filter(Release.sfv == None).filter(
Release.sfv_metablack_id == None)
if category:
query = query.filter(Release.category_id == int(category))
if limit:
releases = query.order_by(Release.posted.desc()).limit(limit)
else:
releases = query.order_by(Release.posted.desc()).all()
for release in releases:
found = False
nzb = pynab.nzbs.get_nzb_details(release.nzb)
if nzb:
sfvs = []
for sfv in nzb['sfvs']:
for part in sfv['segments']:
if int(part['size']) > SFV_MAX_FILESIZE:
continue
sfvs.append(part)
for sfv in sfvs:
try:
article = server.get(release.group.name, [sfv['message_id'], ])
except:
article = None
if article:
data = gzip.compress(article.encode('utf-8'))
sfv = SFV(data=data)
db.add(sfv)
release.sfv = sfv
release.sfv_metablack_id = None
db.add(release)
log.info('sfv: [{}] - sfv added'.format(
release.search_name
))
found = True
break
if not found:
log.debug('sfv: [{}] - no sfvs in release'.format(
release.search_name
))
mb = MetaBlack(sfv=release, status='IMPOSSIBLE')
db.add(mb)
db.commit()
示例14: rename_bad_releases
def rename_bad_releases(category):
count = 0
s_count = 0
for_deletion = []
with db_session() as db:
# noinspection PyComparisonWithNone,PyComparisonWithNone,PyComparisonWithNone,PyComparisonWithNone
query = db.query(Release).filter(Release.category_id==int(category)).filter(
(Release.files.any())|(Release.nfo_id!=None)|(Release.sfv_id!=None)|(Release.pre_id!=None)
).filter((Release.status!=1)|(Release.status==None)).filter(Release.unwanted==False)
for release in windowed_query(query, Release.id, config.scan.get('binary_process_chunk_size', 1000)):
count += 1
name, category_id = pynab.releases.discover_name(release)
if not name and category_id:
# don't change the name, but the category might need changing
release.category_id = category_id
# we're done with this release
release.status = 1
db.merge(release)
elif name and category_id:
# only add it if it doesn't exist already
existing = db.query(Release).filter(Release.name==name,
Release.group_id==release.group_id,
Release.posted==release.posted).first()
if existing:
# if it does, delete this one
for_deletion.append(release.id)
db.expunge(release)
else:
# we found a new name!
s_count += 1
release.name = name
release.search_name = pynab.releases.clean_release_name(name)
release.category_id = category_id
# we're done with this release
release.status = 1
db.merge(release)
else:
# nein
release.status = 0
release.unwanted = True
db.commit()
if for_deletion:
deleted = db.query(Release).filter(Release.id.in_(for_deletion)).delete(synchronize_session=False)
else:
deleted = 0
log.info('rename: successfully renamed {} of {} releases and deleted {} duplicates'.format(s_count, count, deleted))
示例15: process
def process(limit=5, category=0):
"""Process releases for NFO parts and download them."""
log.info('Checking for NFO segments...')
with Server() as server:
query = {'nfo': None}
if category:
query['category._id'] = int(category)
for release in db.releases.find(query).limit(limit).sort('posted', pymongo.DESCENDING).batch_size(50):
log.debug('Checking for NFO in {}...'.format(release['search_name']))
nzb = pynab.nzbs.get_nzb_dict(release['nzb'])
if nzb:
nfos = []
if nzb['nfos']:
for nfo in nzb['nfos']:
if not isinstance(nfo['segments']['segment'], list):
nfo['segments']['segment'] = [nfo['segments']['segment'], ]
for part in nfo['segments']['segment']:
if int(part['@bytes']) > NFO_MAX_FILESIZE:
continue
nfos.append(part)
if nfos:
for nfo in nfos:
try:
article = server.get(release['group']['name'], [nfo['#text'], ])
except:
article = None
if article:
data = gzip.compress(article.encode('utf-8'))
nfo_file = fs.put(data, filename='.'.join([release['name'], 'nfo', 'gz']))
if nfo_file:
db.releases.update({'_id': release['_id']}, {
'$set': {
'nfo': nfo_file
}
})
log.info('Grabbed and saved NFO for: {}'.format(release['name']))
break
else:
log.debug('Error retrieving NFO.')
continue
else:
log.debug('No NFOs found in this release.')
db.releases.update({'_id': release['_id']}, {
'$set': {
'nfo': False
}
})