示例#1
0
def processRequest(req):

    #météo
    if req.get("result").get("action") == "yahooWeatherForecast":
        baseurl = "https://query.yahooapis.com/v1/public/yql?"
        yql_query = makeYqlQuery(req)
        if yql_query is None:
            return {}
        yql_url = baseurl + urlencode({'q': yql_query
                                       }) + "&format=json&lang=fr-FR"
        result = urlopen(yql_url).read()
        data = json.loads(result)
        res = makeWebhookResult(data)
    #météoopen
    elif req.get("result").get("action") == "openweather":
        baseurl = "api.openweathermap.org/data/2.5/weather?"
        owm_query = makeOwmQuery(req)
        #if owm_query is None:
        #return {}
        owm_url = baseurl + urlencode({
            'q': owm_query
        }) + "&lang=fr&APPID=8436a2c87fc4408d01d9f7f92e9759ca"
        result = urlopen(owm_url).read()
        data = json.loads(result)
        res = makeWebhookResultopen(data)
    #sheet exposant
    elif req.get("result").get("action") == "readsheet-exp":
        GsExp_query = makeGsExpQuery(req)
        client = SheetsuClient("https://sheetsu.com/apis/v1.0su/27ac2cb1ff16")
        data = client.search(sheet="Exposant", nom=GsExp_query)
        res = makeWebhookResultForSheetsExp(data)
    #sheet bus
    elif req.get("result").get("action") == "readsheet-bus":
        GsBus_query = makeGsBusQuery(req)
        client = SheetsuClient("https://sheetsu.com/apis/v1.0su/27ac2cb1ff16")
        data = client.search(sheet="Navette", date=GsBus_query)
        res = makeWebhookResultForSheetsBus(data)
    #sheet session
    elif req.get("result").get("action") == "readsheet-ses":
        GsSes_query = makeGsSesQuery(req)
        client = SheetsuClient("https://sheetsu.com/apis/v1.0su/27ac2cb1ff16")
        data = client.search(sheet="Conference", date=GsSes_query)
        res = makeWebhookResultForSheetsSes(data)
    #sheet conference
    elif req.get("result").get("action") == "readsheet-seshor":
        GsSesHor_query = makeGsSesHorQuery(req)
        client = SheetsuClient("https://sheetsu.com/apis/v1.0su/27ac2cb1ff16")
        data = client.search(sheet="Conference", Partner=GsSesHor_query)
        res = makeWebhookResultForSheetsSesHor(data)
    #sheetnow
    elif req.get("result").get("action") == "readsheet-ses-now":
        #GsSesNow_query = makeGsSesNowQuery(req)
        client = SheetsuClient("https://sheetsu.com/apis/v1.0su/27ac2cb1ff16")
        data = client.read(sheet="Conference")
        res = makeWebhookResultForSheetsSesNow(data)

    else:
        return {}

    return res
示例#2
0
    def test_read_with_offset_parameter(self, mock):
        """Ensure that READing works if offset parameter is given"""
        mock.return_value = MagicMock(status_code=200,
                                      content=json.dumps([{
                                          'id': '3',
                                          'name': 'Meg',
                                          'score': '10'
                                      }, {
                                          'id': '4',
                                          'name': 'Chris',
                                          'score': '42'
                                      }, {
                                          'id': '5',
                                          'name': 'Stewie',
                                          'score': '72'
                                      }]))

        client = SheetsuClient(**self.kwargs)
        response = client.read(offset=2)
        self.assertEqual(response, [{
            'id': '3',
            'name': 'Meg',
            'score': '10'
        }, {
            'id': '4',
            'name': 'Chris',
            'score': '42'
        }, {
            'id': '5',
            'name': 'Stewie',
            'score': '72'
        }])
示例#3
0
    def test_read_fail(self, mock):
        """Ensure that if request fails, that proper response is given"""
        mock.return_value = MagicMock(status_code=400)

        client = SheetsuClient(**self.kwargs)
        response = client.read()
        self.assertIsNone(response)
示例#4
0
    def test_read_with_negative_or_zero_limit_parameter(self, mock):
        """Ensure that READing works if limit is negative or zero"""
        mock.return_value = MagicMock(status_code=200,
                                      content=json.dumps([{
                                          'id': '1',
                                          'name': 'Peter',
                                          'score': '42'
                                      }, {
                                          'id': '2',
                                          'name': 'Lois',
                                          'score': '89'
                                      }, {
                                          'id': '3',
                                          'name': 'Meg',
                                          'score': '10'
                                      }, {
                                          'id': '4',
                                          'name': 'Chris',
                                          'score': '42'
                                      }, {
                                          'id': '5',
                                          'name': 'Stewie',
                                          'score': '72'
                                      }]))

        client = SheetsuClient(**self.kwargs)
        # test with an invalid values
        for invalid_value in [-1, 0]:
            response = client.read(limit=invalid_value)
            self.assertEqual(response, [{
                'id': '1',
                'name': 'Peter',
                'score': '42'
            }, {
                'id': '2',
                'name': 'Lois',
                'score': '89'
            }, {
                'id': '3',
                'name': 'Meg',
                'score': '10'
            }, {
                'id': '4',
                'name': 'Chris',
                'score': '42'
            }, {
                'id': '5',
                'name': 'Stewie',
                'score': '72'
            }])
示例#5
0
    def test_simple_read(self, mock):
        """Ensure that simple READ of a spreadsheet using Sheetsu API
        works properly"""
        mock.return_value = MagicMock(status_code=200,
                                      content=json.dumps([{
                                          'id': '1',
                                          'name': 'Peter',
                                          'score': '42'
                                      }, {
                                          'id': '2',
                                          'name': 'Lois',
                                          'score': '89'
                                      }, {
                                          'id': '3',
                                          'name': 'Meg',
                                          'score': '10'
                                      }, {
                                          'id': '4',
                                          'name': 'Chris',
                                          'score': '42'
                                      }, {
                                          'id': '5',
                                          'name': 'Stewie',
                                          'score': '72'
                                      }]))

        client = SheetsuClient(**self.kwargs)
        response = client.read()

        self.assertEqual(response, [{
            'id': '1',
            'name': 'Peter',
            'score': '42'
        }, {
            'id': '2',
            'name': 'Lois',
            'score': '89'
        }, {
            'id': '3',
            'name': 'Meg',
            'score': '10'
        }, {
            'id': '4',
            'name': 'Chris',
            'score': '42'
        }, {
            'id': '5',
            'name': 'Stewie',
            'score': '72'
        }])
def importAssetsFromSheet (SaveImages=True, SaveDocuments=True, UseLocalCache=True) ->bool:
    """Retreive the image from URL ."""
    client = SheetsuClient(SHEETSU_ID)
    db = None
    if (UseLocalCache):
        try:
            # Do we have a pickle?
            with open("./db.pkl", "rb") as f:
                db = pickle.load(f)
                if (len(db) <= 0):
                    print ("Error: Cache was empty. Please recreate the local cache.")
                    return
        except:
            print ("Reading from Sheetsu...")
            try:
                db = client.read(sheet="DB")
            except RuntimeError as err:
                print ("Error: " + err)
                return

        # Let's pickle the damn DB to save some time.
        with open("./db.pkl", "wb") as f:
            pickle.dump (db, f)
    else:
        print ("Reading from local cache...")
        db = client.read(sheet="DB")
        # Let's pickle the damn DB to save some time.
        with open("./db.pkl", "wb") as f:
            pickle.dump (db, f)

    start_index = SHEET_START_POINT
    print ("Starting at " + str(start_index))
    print (str(len(db)) + " Projects...")
    project_name = ''
    project_count = start_index

    for row in db[start_index:]:
        project_count = project_count + 1
        project_name = row['Project']
        external_id = row['external_id']
        print ("================================")
        print ("Working on '" + external_id + "'")
        print ("================================")
        ticker = row['Ticker']
        image_filename = row['Logo']
        whitepaper_url = row['Documentation']
        # check to see if that's a valid filename or not
        url = LOGOS_URL + image_filename
        assetData = {
            "logo": image_filename, 
            "external_id": external_id, 
            "project_name": project_name,
            "ticker": ticker,
            "logo_url": url,
            "whitepaper_url": whitepaper_url
        }

        if (SaveImages):
            if (image_filename != ''):
                if _getImage(assetData):
                    public_url = uploadToGCPStorage (external_id, image_filename, True)
                    if (public_url):
                        print (public_url)
                    else:
                        continue
        if (SaveDocuments):
            if (whitepaper_url != ''):
                Saved, filename, FileTypeCheck = _getDocument(assetData)
                if (Saved == True):
                    public_url = uploadToGCPStorage (external_id, filename, FileTypeCheck)
                    if (public_url):
                        print (public_url)
                else:
                    continue
            else:
                _log("Error: '" + external_id + "' has no white paper url.")
                continue
        print ("================================")
        print ("👉 " + str(project_count) + " of " + str(len(db)) + " Projects...")
        print ("================================")

    print ("Completed")
    return True
示例#7
0
    def test_read_with_limit_parameter(self, mock):
        """Ensure that READing works if limit is given"""
        client = SheetsuClient(**self.kwargs)

        # test with value under the total amount of rows
        mock.return_value = MagicMock(status_code=200,
                                      content=json.dumps([
                                          {
                                              'id': '1',
                                              'name': 'Peter',
                                              'score': '42'
                                          },
                                          {
                                              'id': '2',
                                              'name': 'Lois',
                                              'score': '89'
                                          },
                                      ]))
        response = client.read(limit=2)
        self.assertEqual(response, [{
            'id': '1',
            'name': 'Peter',
            'score': '42'
        }, {
            'id': '2',
            'name': 'Lois',
            'score': '89'
        }])

        # test with value above the total amount of rows
        mock.return_value = MagicMock(status_code=200,
                                      content=json.dumps([{
                                          'id': '1',
                                          'name': 'Peter',
                                          'score': '42'
                                      }, {
                                          'id': '2',
                                          'name': 'Lois',
                                          'score': '89'
                                      }, {
                                          'id': '3',
                                          'name': 'Meg',
                                          'score': '10'
                                      }, {
                                          'id': '4',
                                          'name': 'Chris',
                                          'score': '42'
                                      }, {
                                          'id': '5',
                                          'name': 'Stewie',
                                          'score': '72'
                                      }]))
        response = client.read(limit=10)
        self.assertEqual(response, [{
            'id': '1',
            'name': 'Peter',
            'score': '42'
        }, {
            'id': '2',
            'name': 'Lois',
            'score': '89'
        }, {
            'id': '3',
            'name': 'Meg',
            'score': '10'
        }, {
            'id': '4',
            'name': 'Chris',
            'score': '42'
        }, {
            'id': '5',
            'name': 'Stewie',
            'score': '72'
        }])