Skip to content

Commit 3488540

Browse files
authored
Merge pull request #43 from Paulooh007/create-dotenv
Implement .env for secrets
2 parents 53b477c + 99aebb7 commit 3488540

12 files changed

Lines changed: 101 additions & 48 deletions

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ modules:
4848
[pipenvinstall]: https://pipenv.pypa.io/en/latest/install/#installing-pipenv
4949
5050
51+
### Running Scripts that Require Client Credentials
52+
53+
To successfully run scripts that require client credentials, you will need to follow these steps:
54+
1. Copy the contents of the `env.example` file in the script's directory to `.env`:
55+
```
56+
cp env.example .env
57+
```
58+
2. Uncomment the variables in the `.env` file and assign values as needed. See [`sources.md`](sources.md) on how to get credentials:
59+
```
60+
GOOGLE_API_KEYS=your_api_key
61+
PSE_KEY=your_pse_key
62+
```
63+
3. Save the changes to the `.env` file.
64+
65+
4. You should now be able to run scripts that require client credentials without any issues.
66+
67+
5168
### Tooling
5269
5370
- **[Python Guidelines — Creative Commons Open Source][ccospyguide]**
@@ -64,7 +81,7 @@ modules:
6481
6582
## Data Sources
6683
67-
Kindly visit the [source.md](sources.md) file for it.
84+
Kindly visit the [sources.md](sources.md) file for it.
6885
6986
7087
## History

deviantart/deviantart_scratcher.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,22 @@
1212

1313
# Third-party
1414
import pandas as pd
15-
import query_secrets
1615
import requests
16+
from dotenv import load_dotenv
1717
from requests.adapters import HTTPAdapter
1818
from urllib3.util.retry import Retry
1919

20+
CWD = os.path.dirname(os.path.abspath(__file__))
21+
dotenv_path = os.path.join(os.path.dirname(CWD), ".env")
22+
load_dotenv(dotenv_path)
23+
2024
today = dt.datetime.today()
21-
API_KEYS = query_secrets.API_KEYS
25+
API_KEYS = os.getenv("GOOGLE_API_KEYS").split(",")
2226
API_KEYS_IND = 0
23-
CWD = os.path.dirname(os.path.abspath(__file__))
2427
DATA_WRITE_FILE = (
2528
f"{CWD}" f"/data_deviantart_{today.year}_{today.month}_{today.day}.csv"
2629
)
27-
PSE_KEY = query_secrets.PSE_KEY
30+
PSE_KEY = os.getenv("PSE_KEY")
2831

2932

3033
def get_license_list():

deviantart/query_secrets.example.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

env.example

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## photos.py & photos_detail.py
2+
# "The flickr developer guide: https://www.flickr.com/services/developer/"
3+
4+
# FLICKR_API_KEY =
5+
# FLICKR_API_SECRET =
6+
7+
8+
## deviantart_scratcher.py & google_scratcher.py
9+
# "Custom Search JSON API requires the use of an API key. An API key is a way
10+
# to identify your client to Google."
11+
# https://developers.google.com/custom-search/v1/introduction
12+
13+
# GOOGLE_API_KEYS = key1, key2
14+
15+
# "The identifier of an engine created using the Programmable Search Engine
16+
# Control Panel [https://programmablesearchengine.google.com/about/]"
17+
# https://developers.google.com/custom-search/v1/reference/rest/v1/Search
18+
19+
# PSE_KEY =
20+
21+
22+
## vimeo_scratcher.py
23+
# "Before we set you loose on the API, we ask that you provide a little
24+
# information about your app. An app in this sense can be a full-featured
25+
# mobile application, a dynamic web page, or a three-line script. If it's
26+
# making API calls, it's an app."
27+
# https://developer.vimeo.com/api/guides/start#register-your-app
28+
29+
# VIMEO_ACCESS_TOKEN =
30+
# VIMEO_CLIENT_ID =
31+
32+
33+
## youtube_scratcher.py
34+
# "Every request must either specify an API key (with the key parameter) [...].
35+
# Your API key is available in the Developer Console's API Access pane
36+
# [https://console.developers.google.com/] for your project."
37+
# https://developers.google.com/youtube/v3/docs
38+
39+
# YOUTUBE_API_KEY =
40+
41+

flickr/photos.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
# Standard library
22
import json
3+
import os
34
import os.path
45
import sys
56
import traceback
67

78
# Third-party
89
import flickrapi
9-
import query_secrets
10+
from dotenv import load_dotenv
1011

1112
CWD = os.path.dirname(os.path.abspath(__file__))
13+
dotenv_path = os.path.join(os.path.dirname(CWD), ".env")
14+
load_dotenv(dotenv_path)
1215

1316

1417
def main():
1518
flickr = flickrapi.FlickrAPI(
16-
query_secrets.api_key, query_secrets.api_secret, format="json"
19+
os.getenv("FLICKR_API_KEY"),
20+
os.getenv("FLICKR_API_SECRET"),
21+
format="json",
1722
)
1823

1924
# use search method to pull general photo info under each cc license data

flickr/photos_detail.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
# Standard library
1111
import json
12+
import os
1213
import os.path
1314
import sys
1415
import time
@@ -17,9 +18,12 @@
1718
# Third-party
1819
import flickrapi
1920
import pandas as pd
20-
import query_secrets
21+
from dotenv import load_dotenv
2122

2223
CWD = os.path.dirname(os.path.abspath(__file__))
24+
dotenv_path = os.path.join(os.path.dirname(CWD), ".env")
25+
load_dotenv(dotenv_path)
26+
2327
RETRIES = 0
2428

2529

@@ -149,7 +153,9 @@ def main():
149153
hs_csv_path = os.path.join(CWD, "hs.csv")
150154

151155
flickr = flickrapi.FlickrAPI(
152-
query_secrets.api_key, query_secrets.api_secret, format="json"
156+
os.getenv("FLICKR_API_KEY"),
157+
os.getenv("FLICKR_API_SECRET"),
158+
format="json",
153159
)
154160
# below is the cc licenses list
155161
license_list = [1, 2, 3, 4, 5, 6, 9, 10]

google_custom_search/google_scratcher.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@
1212

1313
# Third-party
1414
import pandas as pd
15-
import query_secrets
1615
import requests
16+
from dotenv import load_dotenv
1717
from requests.adapters import HTTPAdapter
1818
from urllib3.util.retry import Retry
1919

20+
CWD = os.path.dirname(os.path.abspath(__file__))
21+
dotenv_path = os.path.join(os.path.dirname(CWD), ".env")
22+
load_dotenv(dotenv_path)
23+
2024
today = dt.datetime.today()
21-
API_KEYS = query_secrets.API_KEYS
25+
API_KEYS = os.getenv("GOOGLE_API_KEYS").split(",")
2226
API_KEYS_IND = 0
23-
CWD = os.path.dirname(os.path.abspath(__file__))
2427
DATA_WRITE_FILE = (
2528
f"{CWD}"
2629
f"/data_google_custom_search_{today.year}_{today.month}_{today.day}.csv"
@@ -36,7 +39,7 @@
3639
f"{today.year}_{today.month}_{today.day}.csv"
3740
)
3841
SEARCH_HALFYEAR_SPAN = 20
39-
PSE_KEY = query_secrets.PSE_KEY
42+
PSE_KEY = os.getenv("PSE_KEY")
4043

4144

4245
def get_license_list():

google_custom_search/query_secrets.example.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

vimeo/query_secrets.example.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

vimeo/vimeo_scratcher.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@
1414
import traceback
1515

1616
# Third-party
17-
import query_secrets
1817
import requests
18+
from dotenv import load_dotenv
1919
from requests.adapters import HTTPAdapter
2020
from urllib3.util.retry import Retry
2121

22-
today = dt.datetime.today()
23-
ACCESS_TOKEN = query_secrets.ACCESS_TOKEN
24-
CLIENT_ID = query_secrets.CLIENT_ID
2522
CWD = os.path.dirname(os.path.abspath(__file__))
23+
dotenv_path = os.path.join(os.path.dirname(CWD), ".env")
24+
load_dotenv(dotenv_path)
25+
26+
today = dt.datetime.today()
27+
ACCESS_TOKEN = os.getenv("VIMEO_ACCESS_TOKEN")
28+
CLIENT_ID = os.getenv("VIMEO_CLIENT_ID")
2629
DATA_WRITE_FILE = (
2730
f"{CWD}" f"/data_vimeo_{today.year}_{today.month}_{today.day}.csv"
2831
)

0 commit comments

Comments
 (0)