"""Fetch unofficial PATCO feed."""

from datetime import datetime
import logging
import requests

from FeedSource import FeedSource, TIMECHECK_FMT

URL = 'https://api.github.com/repos/flibbertigibbet/patco-gtfs/releases/latest'
FILE_NAME = 'patco.zip'

LAST_UPDATED_FMT = '%Y-%m-%dT%H:%M:%SZ'

LOG = logging.getLogger(__name__)


class Patco(FeedSource):
    """Fetch unofficial PATCO feed."""
    def __init__(self):
        super(Patco, self).__init__()
        self.urls = {'patco.zip': URL}

    def fetch(self):
        """Check GitHub latest release page to see if there is a newer download available."""
        request = requests.get(URL)
        if request.ok:
            response = request.json()
            download_url = response['assets'][0]['browser_download_url']
            last_updated_str = response['assets'][0]['updated_at']
            last_updated = datetime.strptime(last_updated_str, LAST_UPDATED_FMT)
            stat = self.status.get(FILE_NAME)
            if stat:
                got_last = datetime.strptime(stat['posted_date'], TIMECHECK_FMT)
                LOG.debug('PATCO GTFS last fetched: %s, last updated: %s', got_last, last_updated)
                if got_last >= last_updated:
                    LOG.info('No new download available for PATCO.')
                    self.update_existing_status(FILE_NAME)
                    return
            else:
                LOG.info('No previous PATCO download found. Last update posted: %s', last_updated)

            self.fetchone(FILE_NAME, download_url)
            self.set_posted_date(FILE_NAME, last_updated.strftime(TIMECHECK_FMT))
            self.write_status()
        else:
            LOG.error('Could not check GitHub relases page for PATCO.')

@@ -1,31 +1,29 @@
 %22%22%22Fetch 
-un
 official PATCO feed.
@@ -159,135 +159,92 @@
 ://a
-pi.github.com/repos/flibbertigibbet/patco-gtfs/releases/latest'%0AFILE_NAME = 'patco.zip'%0A%0ALAST_UPDATED_FMT = '%25Y-%25m-%25dT%25H:%25M:%25SZ
+ddtransit.com/gtfs/Patco/PortAuthorityTransitCorporation.zip'%0AFILE_NAME = 'patco.zip
 '%0A%0AL
@@ -316,18 +316,16 @@
 %22%22Fetch 
-un
 official
@@ -446,1253 +446,4 @@
 L%7D%0A%0A
-    def fetch(self):%0A        %22%22%22Check GitHub latest release page to see if there is a newer download available.%22%22%22%0A        request = requests.get(URL)%0A        if request.ok:%0A            response = request.json()%0A            download_url = response%5B'assets'%5D%5B0%5D%5B'browser_download_url'%5D%0A            last_updated_str = response%5B'assets'%5D%5B0%5D%5B'updated_at'%5D%0A            last_updated = datetime.strptime(last_updated_str, LAST_UPDATED_FMT)%0A            stat = self.status.get(FILE_NAME)%0A            if stat:%0A                got_last = datetime.strptime(stat%5B'posted_date'%5D, TIMECHECK_FMT)%0A                LOG.debug('PATCO GTFS last fetched: %25s, last updated: %25s', got_last, last_updated)%0A                if got_last %3E= last_updated:%0A                    LOG.info('No new download available for PATCO.')%0A                    self.update_existing_status(FILE_NAME)%0A                    return%0A            else:%0A                LOG.info('No previous PATCO download found. Last update posted: %25s', last_updated)%0A%0A            self.fetchone(FILE_NAME, download_url)%0A            self.set_posted_date(FILE_NAME, last_updated.strftime(TIMECHECK_FMT))%0A            self.write_status()%0A        else:%0A            LOG.error('Could not check GitHub relases page for PATCO.')%0A

Use official PATCO GTFS