예제 #1
0
    def test_simple_create_many(self, mock):
        """Ensure that simple CREATE many method will add a new row to our
        existing a spreadsheet"""
        mock.return_value = MagicMock(status_code=200,
                                      content=json.dumps([{
                                          'id': '1',
                                          'name': 'Peter',
                                          'score': '42'
                                      }, {
                                          'id': '2',
                                          'name': 'Lois',
                                          'score': '89'
                                      }]))

        client = SheetsuClient(**self.kwargs)
        response = client.create_many(*[
            dict(id=1, name="Peter", score=42),
            dict(id=2, name="Louis", score=89)
        ])

        self.assertEqual(response, [{
            'id': '1',
            'name': 'Peter',
            'score': '42'
        }, {
            'id': '2',
            'name': 'Lois',
            'score': '89'
        }])
예제 #2
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)
예제 #3
0
    def test_delete_with_sheet_success(self, mock):
        """Ensure that DELETE works properlly """
        mock.return_value = MagicMock(status_code=204)

        client = SheetsuClient(**self.kwargs)
        response = client.delete(sheet="Sheet1", column="name", value="Meg")
        self.assertIsNone(response)
예제 #4
0
    def test_simple_create_one_different_sheet(self, mock):
        """Ensure that simple CREATE one method will add a new row to our
        specified sheet"""
        mock.return_value = MagicMock(status_code=200,
                                      content=json.dumps([
                                          {
                                              'id': '1',
                                              'name': 'Peter',
                                              'score': '42'
                                          },
                                      ]))

        client = SheetsuClient(**self.kwargs)
        response = client.create_one(sheet="Sheet2",
                                     id=1,
                                     name="Peter",
                                     score=42)

        self.assertEqual(response, [
            {
                'id': '1',
                'name': 'Peter',
                'score': '42'
            },
        ])
예제 #5
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'
        }])
예제 #6
0
    def test_delete_clear_with_bad_response_fail(self, mock):
        """Ensure that DELETE in clear-mode raises an exception when it doesn't get a 204"""
        mock.return_value = MagicMock(status_code=205)

        client = SheetsuClient(**self.kwargs)
        with self.assertRaises(UnexpectedResponseCode):
            response = client.delete(sheet="Sheet1",
                                     column="name",
                                     value="Meg")
예제 #7
0
    def test_search_success(self, mock):
        """Ensure that DELETE works properlly """
        mock.return_value = MagicMock(status_code=200, content=json.dumps([
            {'id': '1', 'name': 'Peter', 'score': '123'}
        ]))

        client = SheetsuClient(**self.kwargs)
        response = client.search(sheet="Sheet", limit=1, offset=1,
                                 ignore_case=True, name="peter")
        self.assertEqual(response, [
            {'id': '1', 'name': 'Peter', 'score': '123'}
        ])
예제 #8
0
    def test_update_success(self, mock):
        """Ensure that DELETE works properlly """
        mock.return_value = MagicMock(status_code=200, content=json.dumps([
            {'id': '1', 'name': 'Peter', 'score': '99'}
        ]))

        client = SheetsuClient(**self.kwargs)
        response = client.update(sheet="Sheet1", column="name", value="Peter",
                                 data={"score": 99})
        self.assertEqual(response, [
            {'id': '1', 'name': 'Peter', 'score': '99'}
        ])
예제 #9
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'
            }])
예제 #10
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'
        }])
예제 #11
0
    def test_delete_with_sheet_success(self, mock):
        """Ensure that DELETE works properlly """
        mock.return_value = MagicMock(status_code=200,
                                      content=json.dumps([{
                                          'id': '5',
                                          'name': 'Stewie',
                                          'score': '72'
                                      }]))

        client = SheetsuClient(**self.kwargs)
        response = client.delete(sheet="Sheet1", column="name", value="Meg")
        self.assertEqual(response, [{
            'id': '5',
            'name': 'Stewie',
            'score': '72'
        }])
예제 #12
0
def processRequest(req):

    #météo
    if req.get("queryResult").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)
    # #sheet exposant
    elif req.get("queryResult").get("action") == "readsheet-exp":
        GsExp_query = makeGsExpQuery(req)
        client = SheetsuClient("https://sheetsu.com/apis/v1.0su/27ac2cb1ff16")
        #à modifier: 'sheet="Exposant"' choisir la sheet correspondante
        data = client.search(sheet="Exposant", nom=GsExp_query)
        res = makeWebhookResultForSheetsExp(data)
    #  #sheet bus
    elif req.get("queryResult").get("action") == "readsheet-bus":
        GsBus_query = makeGsBusQuery(req)
        client = SheetsuClient("https://sheetsu.com/apis/v1.0su/27ac2cb1ff16")
        #à modifier: 'sheet="Navette"' choisir la sheet correspondante
        data = client.search(sheet="Navette", date=GsBus_query)
        res = makeWebhookResultForSheetsBus(data)
    #sheet session
    elif req.get("queryResult").get("action") == "readsheet-ses":
        GsSes_query = makeGsSesQuery(req)
        client = SheetsuClient("https://sheetsu.com/apis/v1.0su/27ac2cb1ff16")
        #à modifier: 'sheet="Conference"' choisir la sheet correspondante
        data = client.search(sheet="Conference", date=GsSes_query)
        res = makeWebhookResultForSheetsSes(data)
    #sheet conference
    elif req.get("queryResult").get("action") == "readsheet-seshor":
        GsSesHor_query = makeGsSesHorQuery(req)
        client = SheetsuClient("https://sheetsu.com/apis/v1.0su/27ac2cb1ff16")
        #à modifier: 'sheet="Conference"' choisir la sheet correspondante
        data = client.search(sheet="Conference", Partner=GsSesHor_query)
        res = makeWebhookResultForSheetsSesHor(data)
    #sheetnow
    # elif req.get("queryResult").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
예제 #13
0
from sheetsu import SheetsuClient
import json
from student import *
from actions import *

clientStudent = SheetsuClient("fa9ce8496310")
clientGrades = SheetsuClient("8efe1f243cb1")

debug = False

if debug:
    DataLocation = "local"


def dataLocate():
    dl = raw_input("Local or Remote: ")
    dl = dl[0].lower()
    if dl == "r":
        return "remote"
    else:
        return dl


try:
    DataLocation
except NameError:
    DataLocation = dataLocate()


def getData(location, fileName, client):
    fileName = fileName + '.json'
예제 #14
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'
        }])
예제 #15
0
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
예제 #16
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
예제 #17
0
from sheetsu import SheetsuClient
import json
client = SheetsuClient("600798ca543a")

output = client.search(sheet="Sheet1")

print output

with open('store.json', 'w') as outfile:
    json.dump(output, outfile)

print "written"