gsr 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
gsr-1.0.0/.gitignore ADDED
@@ -0,0 +1,211 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ #pdm.lock
114
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
115
+ # in version control.
116
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
117
+ .pdm.toml
118
+ .pdm-python
119
+ .pdm-build/
120
+
121
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
122
+ __pypackages__/
123
+
124
+ # Celery stuff
125
+ celerybeat-schedule
126
+ celerybeat.pid
127
+
128
+ # SageMath parsed files
129
+ *.sage.py
130
+
131
+ # Environments
132
+ .env
133
+ .envrc
134
+ .venv
135
+ env/
136
+ venv/
137
+ ENV/
138
+ env.bak/
139
+ venv.bak/
140
+
141
+ # Spyder project settings
142
+ .spyderproject
143
+ .spyproject
144
+
145
+ # Rope project settings
146
+ .ropeproject
147
+
148
+ # mkdocs documentation
149
+ /site
150
+
151
+ # mypy
152
+ .mypy_cache/
153
+ .dmypy.json
154
+ dmypy.json
155
+
156
+ # Pyre type checker
157
+ .pyre/
158
+
159
+ # pytype static type analyzer
160
+ .pytype/
161
+
162
+ # Cython debug symbols
163
+ cython_debug/
164
+
165
+ # PyCharm
166
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
167
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
168
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
169
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
170
+ #.idea/
171
+
172
+ # Abstra
173
+ # Abstra is an AI-powered process automation framework.
174
+ # Ignore directories containing user credentials, local state, and settings.
175
+ # Learn more at https://abstra.io/docs
176
+ .abstra/
177
+
178
+ # Visual Studio Code
179
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
180
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
181
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
182
+ # you could uncomment the following to ignore the entire vscode folder
183
+ # .vscode/
184
+
185
+ # Ruff stuff:
186
+ .ruff_cache/
187
+
188
+ # PyPI configuration file
189
+ .pypirc
190
+
191
+ # Cursor
192
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
193
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
194
+ # refer to https://docs.cursor.com/context/ignore-files
195
+ .cursorignore
196
+ .cursorindexingignore
197
+
198
+ # Marimo
199
+ marimo/_static/
200
+ marimo/_lsp/
201
+ __marimo__/
202
+
203
+ # dev files
204
+ dev/
205
+ main.py
206
+
207
+ # API token files
208
+ credentials*.json
209
+ client*.json
210
+ *.csv
211
+ token.json
gsr-1.0.0/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2025 ritonun
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
gsr-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.4
2
+ Name: gsr
3
+ Version: 1.0.0
4
+ Summary: Google Sheet Downloader
5
+ Project-URL: Homepage, https://github.com/ritonun/gsr
6
+ Project-URL: Issues, https://github.com/ritonun/gsr/issues
7
+ Author-email: ritonun <73615644+ritonun@users.noreply.github.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.12
13
+ Requires-Dist: google-api-python-client==2.172.0
14
+ Requires-Dist: google-auth-httplib2==0.2.0
15
+ Requires-Dist: google-auth-oauthlib==1.2.2
16
+ Description-Content-Type: text/markdown
17
+
18
+ # Google Sheet Reader
19
+
20
+ Connect to your google sheet and export data.
21
+
22
+ To get your API token:
23
+ [Google Sheet Python quickstart](https://developers.google.com/workspace/sheets/api/quickstart/python)
24
+
25
+ ## Install
26
+ ```bash
27
+ python3 -m venv .venv
28
+ source .venv/bin/activate
29
+ pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
30
+ ```
31
+
32
+ ## Example
33
+ ```python
34
+ import gsr
35
+
36
+ if __name__ == '__main__':
37
+ SHEET_ID = 'YOUR_SHEET_ID'
38
+ creds = gsr.get_credentials() # your creds should be name `credentials.json` and put in your working folder
39
+
40
+ for range in ["Sheet1", "Sheet2", "Sheet3"]: # your sheet name
41
+ print(f"GET {range}")
42
+
43
+ values = gsr.connect_to_sheet(creds, SHEET_ID, range)
44
+
45
+ if values is None:
46
+ print(f"Error getting {range}, check your SHEET_ID or range")
47
+ else:
48
+ filename = 'csv_' + range + '.csv'
49
+ with open(filename, 'w') as f:
50
+ for row in values:
51
+ text = str(row) + '\n'
52
+ f.write(text)
53
+ ```
gsr-1.0.0/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Google Sheet Reader
2
+
3
+ Connect to your google sheet and export data.
4
+
5
+ To get your API token:
6
+ [Google Sheet Python quickstart](https://developers.google.com/workspace/sheets/api/quickstart/python)
7
+
8
+ ## Install
9
+ ```bash
10
+ python3 -m venv .venv
11
+ source .venv/bin/activate
12
+ pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
13
+ ```
14
+
15
+ ## Example
16
+ ```python
17
+ import gsr
18
+
19
+ if __name__ == '__main__':
20
+ SHEET_ID = 'YOUR_SHEET_ID'
21
+ creds = gsr.get_credentials() # your creds should be name `credentials.json` and put in your working folder
22
+
23
+ for range in ["Sheet1", "Sheet2", "Sheet3"]: # your sheet name
24
+ print(f"GET {range}")
25
+
26
+ values = gsr.connect_to_sheet(creds, SHEET_ID, range)
27
+
28
+ if values is None:
29
+ print(f"Error getting {range}, check your SHEET_ID or range")
30
+ else:
31
+ filename = 'csv_' + range + '.csv'
32
+ with open(filename, 'w') as f:
33
+ for row in values:
34
+ text = str(row) + '\n'
35
+ f.write(text)
36
+ ```
@@ -0,0 +1 @@
1
+ from .gapi import *
gsr-1.0.0/gsr/gapi.py ADDED
@@ -0,0 +1,57 @@
1
+ # google api
2
+
3
+ import os.path
4
+
5
+ from google.auth.transport.requests import Request
6
+ from google.oauth2.credentials import Credentials
7
+ from google_auth_oauthlib.flow import InstalledAppFlow
8
+ from googleapiclient.discovery import build
9
+ from googleapiclient.errors import HttpError
10
+
11
+ SCOPES = ["https://www.googleapis.com/auth/spreadsheets.readonly"]
12
+
13
+ def get_credentials():
14
+ creds = None
15
+ # token.json automatically created upon first connection. check if it exist
16
+ if os.path.exists("token.json"):
17
+ creds = Credentials.from_authorized_user_file("token.json", SCOPES)
18
+
19
+ # if cred are not valid
20
+ if not creds or not creds.valid:
21
+ print('not valid cred')
22
+ if creds and creds.expired and creds.refresh_token:
23
+ creds.refresh(Request())
24
+ else:
25
+ print('cred')
26
+ flow = InstalledAppFlow.from_client_secrets_file(
27
+ "credentials.json", SCOPES
28
+ )
29
+ creds = flow.run_local_server(port=0)
30
+ # Save the credentials for the next run
31
+ with open("token.json", "w") as token:
32
+ token.write(creds.to_json())
33
+ return creds
34
+
35
+
36
+ def connect_to_sheet(creds: Credentials, spreadsheet_id: str, range: str):
37
+ try:
38
+ service = build("sheets", "v4", credentials=creds)
39
+
40
+ # Call the Sheets API
41
+ sheet = service.spreadsheets()
42
+ result = (
43
+ sheet.values()
44
+ .get(spreadsheetId=spreadsheet_id, range=range)
45
+ .execute()
46
+ )
47
+ values = result.get("values", [])
48
+
49
+ if not values:
50
+ print("No data found.")
51
+ return None
52
+
53
+ return values
54
+
55
+ except HttpError as err:
56
+ print(err)
57
+ return None
@@ -0,0 +1,28 @@
1
+ [project]
2
+ name = "gsr"
3
+ version = "1.0.0"
4
+ authors = [
5
+ { name = "ritonun", email = "73615644+ritonun@users.noreply.github.com" },
6
+ ]
7
+ description = "Google Sheet Downloader"
8
+ readme = "README.md"
9
+ requires-python = ">=3.12"
10
+ classifiers = [
11
+ "Programming Language :: Python :: 3",
12
+ "Operating System :: OS Independent",
13
+ ]
14
+ license = "MIT"
15
+ license-files = ["LICEN[CS]E*"]
16
+ dependencies = [
17
+ "google-api-python-client==2.172.0",
18
+ "google-auth-httplib2==0.2.0",
19
+ "google-auth-oauthlib==1.2.2",
20
+ ]
21
+
22
+ [project.urls]
23
+ Homepage = "https://github.com/ritonun/gsr"
24
+ Issues = "https://github.com/ritonun/gsr/issues"
25
+
26
+ [build-system]
27
+ requires = ["hatchling >= 1.26"]
28
+ build-backend = "hatchling.build"