コード例 #1
0
def get_wp_callender(worpress_url):
    now = datetime.now(JST)
    sdt = now.replace(hour=calendar_day_line,
                      minute=0,
                      second=0,
                      microsecond=0)
    sdt = sdt.strftime('%Y/%m/%dT%H:%MZ')
    edt = (now + timedelta(days=1))
    edt = edt.replace(hour=calendar_day_line - 1,
                      minute=59,
                      second=59,
                      microsecond=0)
    edt = edt.strftime('%Y/%m/%dT%H:%MZ')
    API_URI = 'https://' + worpress_url + '/?rest_route=/tribe/events/v1/events'
    url = API_URI + "&start_date=" + sdt + "&end_date=" + edt
    response = httpget(url)
    if response.status_code != 200:
        dprint("error : " + str(response.status_code))
        return
    wss = json_load(response.text)

    ## crop events because time value is ignored by wpapi
    wk = wss['events']
    wss['events'] = []
    for ev in wk:
        if int(ev['start_date_details']['day']) == now.day and int(
                ev['start_date_details']['hour']) > calendar_day_line:
            wss['events'].append(ev)
        if int(ev['start_date_details']['day']) != now.day and int(
                ev['start_date_details']['hour']) < calendar_day_line:
            wss['events'].append(ev)

    return wss
コード例 #2
0
def grab_ultimaker(printerip):
    """
    NOTE: This returns the whole requests HTTP get object
    """
    imgloc = "http://%s:8080/?action=snapshot" % (printerip)

    # I don't care much about the filename since I operate on the actual
    #   image itself (in img.content), but it's nice to save
    outfile = "instasnap.jpg"
    print("Attempting to write image to %s" % (outfile))

    with open(outfile, "wb") as f:
        img = httpget(imgloc, timeout=5.)
        # Check the HTTP response;
        #   200 - 400 == True
        #   400 - 600 == False
        #   Other way to do it might be to check if img.status_code == 200
        if img.ok is True:
            print("Good grab!")
            f.write(img.content)
        else:
            # This will be caught elsewhere
            print("Bad grab :(")
            img = None
            raise RCE

    return img
コード例 #3
0
ファイル: grab_cams.py プロジェクト: tbowers7/NightShift
def camGrabbie(cam, outfile):
    """
    Grab an image from an individual camera as defined by the Webcam class
    """
    if cam.auth.lower() == 'digest':
        auth = HTTPDigestAuth(cam.user, cam.password)
    else:
        auth = HTTPBasicAuth(cam.user, cam.password)

    # NOTE: This'll barf if the directory (cam.floc) doesn't exist.
    #   Make sure to do that check in your calling code!
    print("Attempting to write image to %s" % (outfile))
    with open(outfile, "wb") as f:
        img = httpget(cam.url, auth=auth, timeout=5.)
        # Check the HTTP response;
        #   200 - 400 == True
        #   400 - 600 == False
        #   Other way to do it might be to check if img.status_code == 200
        # NOTE: I needed to add this check because one webcam went
        #   *mostly dead* and returned HTTP codes and pings, but not images.
        if img.ok is True:
            print("Good grab!")
            f.write(img.content)
        else:
            # This will be caught elsewhere
            print("Bad grab :(")
            raise RCE
コード例 #4
0
def simpleImageCopy(url, location, failimg):
    """
    Download the file from the given URL to the given location.
    If that fails, copy the specified failure image to the location instead.
    """

    if url is None:
        failed = True
    else:
        failed = False

    # NOTE: This'll barf if the directory (cam.floc) doesn't exist.
    #   Make sure to do that check in your calling code!
    print("Attempting to write image to %s" % (location))
    with open(location, "wb") as f:
        if failed is False:
            try:
                print('Retrieving image from: %s' % (url))
                img = httpget(url)
                f.write(img.content)
            except RCE as err:
                print(str(err))
                failed = True
        else:
            print("Failed to find the latest image!")
            shutil.copy(failimg, location)
コード例 #5
0
ファイル: grab_cams.py プロジェクト: tbowers7/NightShift
def listFD(url, fmask):
    try:
        page = httpget(url, timeout=10.).text
    except Exception as err:
        # Can't find what exception the timeout raises, so catch everything
        #   for now and then go back in and put the correct one into there.
        print(str(err))
        page = None
        urls = None

    # fmask in the .conf file should be a vaild python RE specification!!
    searcher = re.compile(fmask)

    if page is not None:
        soup = BeautifulSoup(page, 'html.parser')
        urls = []
        for node in soup.find_all('a'):
            nodehref = node.get('href')
            # Now filter based on our given filemask
            #   Easiest to use just a regular expression
            searchresult = searcher.match(nodehref)
            if searchresult is not None:
                urls.append(url + '/' + node.get('href'))

    return urls
コード例 #6
0
def tradingview_transport(url=TRADINGVIEW_CHAT):  ##{
    while True:
        print("\nConnecting to tradingview...")
        try:
            tmp = httpget(url, stream=True, timeout=CONNECTION_TIMEOUT)
            print("Connected")
            yield tmp
        except Exception, e:
            print("[!!!] Esteblish connection error: ", e)
            sleep(3)
コード例 #7
0
def tradingview_transport(url=TRADINGVIEW_CHAT):##{
    while True:
        print("\nConnecting to tradingview...")
        try:
            tmp = httpget(url, stream=True, timeout=CONNECTION_TIMEOUT)
            print("Connected")
            yield tmp
        except Exception, e:
            print("[!!!] Esteblish connection error: ", e)
            sleep(3)
コード例 #8
0
def get_users_from_biling() -> list:
    credentials = httpget(
        'https://web-domain/api/gateways/fetch_customers_srvnet_credentials_by_gw/',
        {'gw_id': 7},
        headers={
            'Authorization': 'Token ffffffffffffffffffffffffffffffffffff',
            'Content-type': 'application/json'
        })
    if credentials.status_code != 200:
        exit(1)
    return credentials.json()
コード例 #9
0
ファイル: grab_cams.py プロジェクト: tbowers7/NightShift
def simpleImageCopy(url, location):
    """
    Download the file from the given URL to the given location.
       NOTE: The download failure condition will be handled elsewhere.
    """

    if url is None:
        raise RCE

    # NOTE: This'll barf if the directory (cam.floc) doesn't exist.
    #   Make sure to do that check in your calling code!
    print("Attempting to write image to %s" % (location))
    with open(location, "wb") as f:
        print('Retrieving image from: %s' % (url))
        img = httpget(url)
        f.write(img.content)
コード例 #10
0
def camGrabbie(cam, outfile):
    """
    Grab an image from an individual camera as defined by the Webcam class
    """
    if cam.auth.lower() == 'digest':
        auth = HTTPDigestAuth(cam.user, cam.password)
    else:
        auth = HTTPBasicAuth(cam.user, cam.password)

    # NOTE: This'll barf if the directory (cam.floc) doesn't exist.
    #   Make sure to do that check in your calling code!
    print("Attempting to write image to %s" % (outfile))
    with open(outfile, "wb") as f:
        try:
            img = httpget(cam.url, auth=auth, timeout=5.)
            # Check the HTTP response;
            #   200 - 400 == True
            #   400 - 600 == False
            #   Other way to do it might be to check if img.status_code == 200
            # NOTE: I needed to add this check because one webcam went
            #   *mostly dead* and returned HTTP codes and pings, but not images
            if img.ok is True:
                f.write(img.content)
                print("Good grab and write to disk as %s!" % (outfile))
            else:
                # This will be caught elsewhere
                print("Bad grab :(")
                raise RCE
        except RTO as err:
            print("Bad grab :(")
            print(str(err))
            raise RCE

    # Test to make sure the image wasn't 0 bytes!
    #   Can happen if the request succeeds but the camera is
    #   being weird and mid-boot or some other intermittent quirk
    imgSize = os.stat(outfile).st_size
    if imgSize == 0:
        print("Saved image was 0 bytes - it was really a bad grab :(")
        raise RCE
コード例 #11
0
def simpleImageCopy(url, location):
    """
    Download the file from the given URL to the given location.
       NOTE: The download failure condition will be handled elsewhere.
    """

    if url is None:
        raise RCE

    # NOTE: This'll barf if the directory (cam.floc) doesn't exist.
    #   Make sure to do that check in your calling code!
    print("Attempting to write image to %s" % (location))
    with open(location, "wb") as f:
        print('Retrieving image from: %s' % (url))
        img = httpget(url)
        f.write(img.content)

    # Test to make sure the image wasn't 0 bytes!
    #   Can happen if the request succeeds but the camera is
    #   being weird and mid-boot or some other intermittent quirk
    imgSize = os.stat(location).st_size
    if imgSize == 0:
        print("Saved image was 0 bytes - it was really a bad grab :(")
        raise RCE
コード例 #12
0
from requests import get as httpget
from xml.etree.ElementTree import fromstring as xmlparse
import argparse
from sys import exit

parser = argparse.ArgumentParser(description='Fetch values.xml from poseidon device and try to parse it')
parser.add_argument('--host', help='the host to check')
args = parser.parse_args()

if not args.host:
  print Exception('You need to specify a hostname')
  exit(-1)

link = 'http://%s/values.xml' % args.host
poseidonxml = httpget(link)

if poseidonxml.status_code == 200:
  xml = xmlparse(poseidonxml.text)
  devicename = xml.findall('Agent/DeviceName').pop().text
  senset = xml.findall('SenSet').pop()
  print('%s:' % devicename)
  for child in senset.getchildren():
    sensor = {
      'id': child.findall('ID').pop().text,
      'name': child.findall('Name').pop().text,
      'min': child.findall('Min').pop().text,
      'max': child.findall('Max').pop().text,
      'units': child.findall('Units').pop().text,
      'value': child.findall('Value').pop().text,
    }