def __init__(self):
     """
     Initializes
         self.api - object with which to call Stocktime Series service endpoints
     """
     super(StocktimeSeriesTestCase, self).__init__()
     self.api = ApiRequest()
     self.logger.info("End of StocktimeSeriesTestCase__init__() ")
Ejemplo n.º 2
0
    def request_events(self, city=None, category=None, date_and_time=None, city_num=10, radius="1"):
        apirequst_object = ApiRequest()
        all_events = ""
        events = ""
        for source in apirequst_object.get_sources():
            if source == "meetup":
                events = self.meetup_response(city, category, date_and_time, city_num, radius)
            elif source == "eventbrite":
                events = self.eventbrite_response(city, category, date_and_time)

            all_events += events
        return all_events
Ejemplo n.º 3
0
def log_data(data):
    host = config[env]['host']
    port = config[env]['port']
    path = config[env]['path']
    url = 'https://' + host + ':' + port + path

    try:
        data['temperature'] = float(data['temperature'])
    except:
        data['temperature'] = ''

    try:
        data['light'] = float(data['light'])
    except:
        data['light'] = ''

    try:
        data['sound'] = float(data['sound'])
    except:
        data['sound'] = ''

    data['humidity'] = ''
    data['device'] = cpx_device
    data['key'] = config[env]['key']
    data['readingTime'] = data['readingTime']

    print("LOGGING DATA")
    print("Post request to:", url)
    response = ApiRequest.make_api_post_request(
        url, data, verify=(False if env == 'dev' else True))
    print("Response:", response)

    return response
Ejemplo n.º 4
0
class DailyTreatEventsHandler(webapp2.RequestHandler):
    obj = SearchEventsUsingAPI()
    api_obj = ApiRequest()

    def get(self):
        self.response.write('Welcome to attender server! Here is a cron job for pulling events from sorces: meetup.com and evenbrite.com')

        ev = Event()
        at = Attendings()
        logging.info("Adding new events to DataStore")
        results = self.obj.request_events(radius="25")
        logging.info("Events added: {}".format(results))
        logging.info("Deleting old events from DataStore")

        #Delete passed events
        qe = ev.return_all_events()
        results = qe.filter(Event.date < datetime.now())
        for res in results:
            logging.info(str(res.key.id()))
            old_attending = Attendings.query(Attendings.event_id == int(res.key.id())).get()
            logging.info("query {}".format(old_attending))
            if old_attending is not None:
                old_attending.key.delete()
            res.key.delete()


        #Update city names
        for q in qe:
            changed = self.api_obj.check_city(q.city)
            if changed:
                q.city = changed
                q.put()
Ejemplo n.º 5
0
    def request_events(self,
                       city=None,
                       category=None,
                       date_and_time=None,
                       city_num=10,
                       radius="1"):
        apirequst_object = ApiRequest()
        all_events = ""
        events = ""
        for source in apirequst_object.get_sources():
            if source == 'meetup':
                events = self.meetup_response(city, category, date_and_time,
                                              city_num, radius)
            elif source == 'eventbrite':
                events = self.eventbrite_response(city, category,
                                                  date_and_time)

            all_events += events
        return all_events
class StocktimeSeriesTestCase(FrameworkTestCase):
    """
    Parent class for all the Stock Time Series Api Requests.
    """

    def __init__(self):
        """
        Initializes
            self.api - object with which to call Stocktime Series service endpoints
        """
        super(StocktimeSeriesTestCase, self).__init__()
        self.api = ApiRequest()
        self.logger.info("End of StocktimeSeriesTestCase__init__() ")

    def setup(self):
        super(StocktimeSeriesTestCase, self).setup()
        
    def teardown(self):
        super(StocktimeSeriesTestCase, self).teardown()

    def stocktime_get(self, endpoint):
        """
        stocktime_get will perform a GET to an stocktime series endpoint
        the endpoint string normally will contain a beginning '/' character.
        """

        return self.api.request('GET', endpoint)

    def stocktime_post(self, endpoint, payload):
        """
        stocktime_post will perform a POST to a stocktime series endpoint with a payload.
        The endpoint string normally will contain a beginning '/' character.
        The payload object will typically, depending on the endpoint, be a JSON object
        """

        return self.api.request('POST', endpoint, payload)
Ejemplo n.º 7
0
    def request(cls, action_data={}, method='GET'):
        # type: (object, object) -> object
        domain, params_string = ApiRequest.build_url(action_data)

        # print(domain + '/?'+params_string)
        try:
            if method == 'GET':
                r = requests.request('get',
                                     domain + '/?' + params_string,
                                     verify=False)
            elif method == 'POST':
                r = requests.request('post',
                                     domain + '/?' + params_string,
                                     verify=False)
            else:
                raise Exception("请求方式有误")
            return cls.parse(r.content)
        except Exception as e:
            print(e)
Ejemplo n.º 8
0
 def build_bundle(self, request=None):
     """
     for now this for testing purpose
     """
     return ApiRequest(request=request)
Ejemplo n.º 9
0
    'lng': -120.38485
}, {
    'station_id': 'SE793',
    'lat': 33.78849,
    'lng': -118.37804
}, {
    'station_id': 'SE574',
    'lat': 34.14406,
    'lng': -116.40036
}, {
    'station_id': 'SE283',
    'lat': 34.90743,
    'lng': -118.52388
}, {
    'station_id': 'SE278',
    'lat': 36.05461,
    'lng': -118.74505
}]

for station in stations:
    # Request api for each station
    location = ApiRequest(station['station_id'], station['lat'],
                          station['lng'])
    location_data = location.get_api_request()

    # Send to topic 'datastation'
    producer.send('datastation', value=location_data)
    print(location_data)

    sleep(10)