mylar/mylar/sabparse.py

62 lines
2.0 KiB
Python
Raw Normal View History

import mylar
from mylar import logger
2016-09-07 04:04:42 +00:00
import requests
from bs4 import BeautifulSoup, UnicodeDammit
import re
import datetime
import sys
from decimal import Decimal
from HTMLParser import HTMLParseError
from time import strptime
def sabnzbd():
SAB_USERNAME = mylar.SAB_USERNAME
SAB_PASSWORD = mylar.SAB_PASSWORD
SAB_HOST = mylar.SAB_HOST #'http://localhost:8085/'
if SAB_USERNAME is None or SAB_PASSWORD is None:
logger.fdebug('No Username / Password specified for SABnzbd. Unable to auto-retrieve SAB API')
if 'https' not in SAB_HOST:
sabhost = re.sub('http://', '', SAB_HOST)
sabhttp = 'http://'
else:
sabhost = re.sub('https://', '', SAB_HOST)
sabhttp = 'https://'
if not sabhost.endswith('/'):
#sabhost = sabhost[:len(sabhost)-1].rstrip()
sabhost = sabhost + '/'
sabline = sabhttp + SAB_USERNAME + ':' + SAB_PASSWORD + '@' + sabhost
r = requests.get(sabline + 'config/general/')
soup = BeautifulSoup(r.content)
#lenlinks = len(cntlinks)
2015-05-22 08:32:51 +00:00
cnt1 = len(soup.findAll("div", {"class": "field-pair alt"}))
cnt2 = len(soup.findAll("div", {"class": "field-pair"}))
cnt = int(cnt1 + cnt2)
n = 0
n_even = -1
n_odd = -1
2015-05-22 08:32:51 +00:00
while (n < cnt):
if n%2==0:
n_even+=1
2015-05-22 08:32:51 +00:00
resultp = soup.findAll("div", {"class": "field-pair"})[n_even]
else:
n_odd+=1
2015-05-22 08:32:51 +00:00
resultp = soup.findAll("div", {"class": "field-pair alt"})[n_odd]
2015-05-22 08:32:51 +00:00
if resultp.find("label", {"for": "nzbkey"}):
#logger.fdebug resultp
try:
2015-05-22 08:32:51 +00:00
result = resultp.find("input", {"type": "text"})
except:
continue
if result['id'] == "nzbkey":
2015-05-22 08:32:51 +00:00
nzbkey = result['value']
logger.fdebug('found SABnzbd NZBKey: ' + str(nzbkey))
return nzbkey
n+=1
#if __name__ == '__main__':
# sabnzbd()