Skip to content

Commit e570746

Browse files
ozgurkaraaslanOzgurOzgur
authored
feat: google sheets (#102)
* feat: the file is created. * feat: GoogleSheets class initialization * chore: google_sheets app example init * feat: GoogleSheet instance is added * feat: get_data method is added. * chore: get_data example is added. * fix: fix the variable named 'url' * feat: add header for authorization operation and configure the output of get_data() method * docs: update comment lines for new config parameters * fix: remove unused api parameter named dateTimeRenderOption * chore: delete create_sheet() method * chore: delete unused example file * chore: add post_data example for Google Sheets support * docs: update docstring according to the new config.json structure * feat: add post_data() method for posting data to a Google Sheet document * refactor: update get_data for less config parameter need * docs: update docstring for the new config format * feat: add_row method for appending new row to the Google Sheet document * feat: add_row method usage example * refactor: update post_data for less config parameter need * docs: update docstring for the new config format * feat: create_sheet method for creating new spreadsheet and sheets * feat: create_sheet method usage example and documentation * feat: delete_data method for deleting targeted or all datas of the table * feat: delete_data method usage example and documentation * refactor: remove the line of debug level setting * fix: resolve read response timeout problem and add update data * fix: format arrangements and docstring correlation * refactor: update file name * docs: update docstring * feat: add access token function and organize codes * docs: updace docstring according to the last specifications * feat: change structure and add doctring * fix: bug fix on create_sheet method * feat: arrange method outputs * test: add tests * feat: auth generate add * feat: update get_data * Revert "test: add tests" This reverts commit 42c64e0. * Revert "feat: auth generate add" This reverts commit 4af7d39. * test: add Google Sheet App test file * feat: add generate_header function * fix: fix generate auth code step output * fix: arrange function parameters * docs: delete the unnecessary config parameter * feat: add generating access token automatically when expire * doc: document fixes * style: pep-8 arrangement * chore: user example arrangements * feat: add step updating functions * feat: arrangements for new methods of manager * fix: add else situation for get_data function result * fix: arrange http requests parameters * fix: arrange http requests parameters * feat: enhance add_row method * fix: fix the bug about partial loss of incoming data * fix: arrange the function inputs * fix: delete the debug_mode(0) line * docs: example docs update * docs: example docs update * feat: add auto spreadsheed_id update after execution of create_sheet method and update methods output formats * chore: add macos ignore files * fix: fix infinite loop error while running sm * refactor: remove fault response parameters from request steps * fix: fix access token result parsing --------- Co-authored-by: Ozgur <ozgur@Ozgur-MacBook-Air.local> Co-authored-by: Ozgur <ozgur@Ozgur-Air.mshome.net>
1 parent 125d0fa commit e570746

File tree

9 files changed

+1260
-0
lines changed

9 files changed

+1260
-0
lines changed

examples/google_sheets/add_data.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Example code for data adding or updating operations of a Google Sheets table with using its API.
3+
4+
Example Configuration
5+
---------------------
6+
Create a config.json file in the root directory of the PicoLTE device.
7+
config.json file must include the following parameters for this example:
8+
9+
config.json
10+
{
11+
"google_sheets":{
12+
"api_key": "[API_KEY]",
13+
"spreadsheetId": "[SPREAD_SHEET_ID]",
14+
"client_id": "[CLIENT_ID]",
15+
"client_secret": "[CLIENT_SECRET]",
16+
"refresh_token": "[REFRESH_TOKEN]"
17+
}
18+
}
19+
20+
"""
21+
from pico_lte.core import PicoLTE
22+
from pico_lte.common import debug
23+
24+
picoLTE = PicoLTE()
25+
26+
debug.info("Adding data to the Google Sheets table...")
27+
result = picoLTE.google_sheets.add_data(
28+
sheet="Sheet1", data=[[1, 2, 3], [4, 5, 6]], data_range="A1:C2"
29+
)
30+
debug.info("Result:", result)

examples/google_sheets/add_row.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
Example code for appending new row to a Google Sheets table with using its API.
3+
4+
Example Configuration
5+
---------------------
6+
Create a config.json file in the root directory of the PicoLTE device.
7+
config.json file must include the following parameters for this example:
8+
9+
config.json
10+
{
11+
"google_sheets":{
12+
"api_key": "[API_KEY]",
13+
"spreadsheetId": "[SPREAD_SHEET_ID]",
14+
"client_id": "[CLIENT_ID]",
15+
"client_secret": "[CLIENT_SECRET]",
16+
"refresh_token": "[REFRESH_TOKEN]"
17+
}
18+
}
19+
20+
"""
21+
from pico_lte.core import PicoLTE
22+
from pico_lte.common import debug
23+
24+
picoLTE = PicoLTE()
25+
26+
debug.info("Appending new row to the Google Sheets table...")
27+
result = picoLTE.google_sheets.add_row(sheet="Sheet1", data=[[1, 2, 3, 4]])
28+
debug.info("Result:", result)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Example code for creating a new Google Sheets spreadsheet and its sheets with using its API.
3+
4+
Example Configuration
5+
---------------------
6+
Create a config.json file in the root directory of the PicoLTE device.
7+
config.json file must include the following parameters for this example:
8+
9+
config.json
10+
{
11+
"google_sheets":{
12+
"api_key": "[API_KEY]",
13+
"client_id": "[CLIENT_ID]",
14+
"client_secret": "[CLIENT_SECRET]",
15+
"refresh_token": "[REFRESH_TOKEN]"
16+
}
17+
}
18+
"""
19+
from pico_lte.core import PicoLTE
20+
from pico_lte.common import debug
21+
22+
picoLTE = PicoLTE()
23+
24+
debug.info("Creating a new Google Sheets spreadsheet and its sheets...")
25+
result = picoLTE.google_sheets.create_sheet(sheets=["Sheet1", "Sheet2"])
26+
debug.info("Result:", result)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Example code for deleting targeted datas of a Google Sheets table with using its API.
3+
4+
Example Configuration
5+
---------------------
6+
Create a config.json file in the root directory of the PicoLTE device.
7+
config.json file must include the following parameters for this example:
8+
9+
config.json
10+
{
11+
"google_sheets":{
12+
"api_key": "[API_KEY]",
13+
"spreadsheetId": "[SPREAD_SHEET_ID]",
14+
"client_id": "[CLIENT_ID]",
15+
"client_secret": "[CLIENT_SECRET]",
16+
"refresh_token": "[REFRESH_TOKEN]"
17+
}
18+
}
19+
"""
20+
from pico_lte.core import PicoLTE
21+
from pico_lte.common import debug
22+
23+
picoLTE = PicoLTE()
24+
25+
debug.info("Cleaning data from the Google Sheets table...")
26+
result = picoLTE.google_sheets.delete_data(sheet="Sheet1", data_range="A1:C2")
27+
debug.info("Result:", result)

examples/google_sheets/get_data.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Example code for getting data from a Google Sheets table with using its API.
3+
4+
Example Configuration
5+
---------------------
6+
Create a config.json file in the root directory of the PicoLTE device.
7+
config.json file must include the following parameters for this example:
8+
9+
config.json
10+
{
11+
"google_sheets":{
12+
"api_key": "[API_KEY]",
13+
"spreadsheetId": "[SPREAD_SHEET_ID]",
14+
"client_id": "[CLIENT_ID]",
15+
"client_secret": "[CLIENT_SECRET]",
16+
"refresh_token": "[REFRESH_TOKEN]"
17+
}
18+
}
19+
20+
"""
21+
from pico_lte.core import PicoLTE
22+
from pico_lte.common import debug
23+
24+
picoLTE = PicoLTE()
25+
26+
debug.info("Getting data from the Google Sheets table...")
27+
result = picoLTE.google_sheets.get_data(sheet="Sheet1", data_range="A1:C2")
28+
debug.info("Result:", result)
29+
30+
# Values can be accessed as a list with "response" key of "result" dictionary: values = result["response"]

0 commit comments

Comments
 (0)