Skip to content

Commit 918aeaa

Browse files
committed
ran black on individual files first
pre-commit with black formatting
1 parent 898bc18 commit 918aeaa

File tree

5 files changed

+70
-78
lines changed

5 files changed

+70
-78
lines changed

examples/requests_adafruit_discord_active_online.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# SPDX-FileCopyrightText: 2022 DJDevon3
1+
# SPDX-FileCopyrightText: 2022 DJDevon3 for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33
# Coded for Circuit Python 8.0
44
"""DJDevon3 Adafruit Feather ESP32-S2 Adafruit_Discord_Active_Users_Example"""
5-
# pylint: disable=line-too-long
65
import gc
76
import re
87
import time
@@ -41,17 +40,15 @@
4140
sleep_time_conversion = "days"
4241

4342
# https://img.shields.io/discord/327254708534116352.svg
44-
ADA_DISCORD_SVG = (
45-
"https://img.shields.io/discord/327254708534116352.json"
46-
)
43+
ADA_DISCORD_SVG = "https://img.shields.io/discord/327254708534116352.json"
4744

4845
# Connect to Wi-Fi
4946
print("\n===============================")
5047
print("Connecting to WiFi...")
5148
requests = adafruit_requests.Session(pool, ssl.create_default_context())
5249
while not wifi.radio.ipv4_address:
5350
try:
54-
wifi.radio.connect(secrets['ssid'], secrets['password'])
51+
wifi.radio.connect(secrets["ssid"], secrets["password"])
5552
except ConnectionError as e:
5653
print("Connection Error:", e)
5754
print("Retrying in 10 seconds")
@@ -72,17 +69,17 @@
7269
except ConnectionError as e:
7370
print("Connection Error:", e)
7471
print("Retrying in 10 seconds")
75-
72+
7673
# Print Full JSON to Serial
77-
full_ada_SVG_json_response = True # Change to true to see full response
74+
full_ada_SVG_json_response = True # Change to true to see full response
7875
if full_ada_SVG_json_response:
7976
ada_SVG_dump_object = json.dumps(ada_SVG_response)
8077
print("JSON Dump: ", ada_SVG_dump_object)
81-
78+
8279
# Print Debugging to Serial
83-
ada_SVG_debug = True # Set to True to print Serial data
80+
ada_SVG_debug = True # Set to True to print Serial data
8481
if ada_SVG_debug:
85-
ada_SVG_users = ada_SVG_response['value']
82+
ada_SVG_users = ada_SVG_response["value"]
8683
print("SVG Value: ", ada_SVG_users)
8784
regex = " online"
8885
replace_with_nothing = ""
@@ -94,7 +91,7 @@
9491
print("Next Update in %s %s" % (int(sleep_int), sleep_time_conversion))
9592
print("===============================")
9693
gc.collect()
97-
# pylint: disable=broad-except
94+
9895
except (ValueError, RuntimeError) as e:
9996
print("Failed to get data, retrying\n", e)
10097
time.sleep(60)

examples/requests_api_discord.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# SPDX-FileCopyrightText: 2022 DJDevon3
1+
# SPDX-FileCopyrightText: 2022 DJDevon3 for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33
# Coded for Circuit Python 8.0
44
"""DJDevon3 Adafruit Feather ESP32-S2 Discord_API_Example"""
5-
# pylint: disable=line-too-long
65
import gc
76
import time
87
import ssl
@@ -44,10 +43,10 @@
4443
sleep_int = sleep_time / 60 / 60 / 24
4544
sleep_time_conversion = "days"
4645

47-
discord_header = {'Authorization': '' + secrets['Discord_Authorization']}
46+
discord_header = {"Authorization": "" + secrets["Discord_Authorization"]}
4847
ADA_SOURCE = (
4948
"https://discord.com/api/v10/guilds/"
50-
+ secrets['Discord_Adafruit_Channel']
49+
+ secrets["Discord_Adafruit_Channel"]
5150
+ "/preview"
5251
)
5352

@@ -57,7 +56,7 @@
5756
requests = adafruit_requests.Session(pool, ssl.create_default_context())
5857
while not wifi.radio.ipv4_address:
5958
try:
60-
wifi.radio.connect(secrets['ssid'], secrets['password'])
59+
wifi.radio.connect(secrets["ssid"], secrets["password"])
6160
except ConnectionError as e:
6261
print("Connection Error:", e)
6362
print("Retrying in 10 seconds")
@@ -67,7 +66,9 @@
6766

6867
while True:
6968
try:
70-
print("\nAttempting to GET DISCORD PREVIEW!") # --------------------------------
69+
print(
70+
"\nAttempting to GET DISCORD PREVIEW!"
71+
) # --------------------------------
7172
# Print Request to Serial
7273
debug_request = False # Set true to see full request
7374
if debug_request:
@@ -78,30 +79,30 @@
7879
except ConnectionError as e:
7980
print("Connection Error:", e)
8081
print("Retrying in 10 seconds")
81-
82+
8283
# Print Full JSON to Serial
8384
discord_debug_response = False # Change to true to see full response
8485
if discord_debug_response:
8586
ada_discord_dump_object = json.dumps(ada_res)
8687
print("JSON Dump: ", ada_discord_dump_object)
87-
88+
8889
# Print keys to Serial
8990
discord_debug_keys = True # Set to True to print Serial data
9091
if discord_debug_keys:
91-
92-
ada_discord_all_members = ada_res['approximate_member_count']
92+
93+
ada_discord_all_members = ada_res["approximate_member_count"]
9394
print("Members: ", ada_discord_all_members)
94-
95-
ada_discord_all_members_online = ada_res['approximate_presence_count']
95+
96+
ada_discord_all_members_online = ada_res["approximate_presence_count"]
9697
print("Online: ", ada_discord_all_members_online)
97-
98+
9899
print("Monotonic: ", time.monotonic())
99100

100101
print("\nFinished!")
101102
print("Next Update in %s %s" % (int(sleep_int), sleep_time_conversion))
102103
print("===============================")
103104
gc.collect()
104-
# pylint: disable=broad-except
105+
105106
except (ValueError, RuntimeError) as e:
106107
print("Failed to get data, retrying\n", e)
107108
time.sleep(60)

examples/requests_api_github.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# SPDX-FileCopyrightText: 2022 DJDevon3
1+
# SPDX-FileCopyrightText: 2022 DJDevon3 for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33
# Coded for Circuit Python 8.0
44
"""DJDevon3 Adafruit Feather ESP32-S2 Github_API_Example"""
5-
# pylint: disable=line-too-long
65
import gc
76
import time
87
import ssl
@@ -12,7 +11,7 @@
1211
import adafruit_requests
1312

1413
# Github developer token required.
15-
# Ensure these are uncommented and in secrets.py or .env
14+
# Ensure these are uncommented and in secrets.py or .env
1615
# "Github_username": "Your Github Username",
1716
# "Github_token": "Your long API token",
1817

@@ -42,19 +41,16 @@
4241
sleep_int = sleep_time / 60 / 60 / 24
4342
sleep_time_conversion = "days"
4443

45-
github_header = {'Authorization':' token ' + secrets["Github_token"]}
46-
GH_SOURCE = (
47-
"https://api.github.com/users/"
48-
+ secrets["Github_username"]
49-
)
44+
github_header = {"Authorization": " token " + secrets["Github_token"]}
45+
GH_SOURCE = "https://api.github.com/users/" + secrets["Github_username"]
5046

5147
# Connect to Wi-Fi
5248
print("\n===============================")
5349
print("Connecting to WiFi...")
5450
requests = adafruit_requests.Session(pool, ssl.create_default_context())
5551
while not wifi.radio.ipv4_address:
5652
try:
57-
wifi.radio.connect(secrets['ssid'], secrets['password'])
53+
wifi.radio.connect(secrets["ssid"], secrets["password"])
5854
except ConnectionError as e:
5955
print("Connection Error:", e)
6056
print("Retrying in 10 seconds")
@@ -75,33 +71,33 @@
7571
except ConnectionError as e:
7672
print("Connection Error:", e)
7773
print("Retrying in 10 seconds")
78-
74+
7975
# Print Response to Serial
8076
debug_response = False # Set true to see full response
8177
if debug_response:
8278
dump_object = json.dumps(github_response)
8379
print("JSON Dump: ", dump_object)
84-
80+
8581
# Print Keys to Serial
86-
gh_debug_keys = True # Set True to print Serial data
82+
gh_debug_keys = True # Set True to print Serial data
8783
if gh_debug_keys:
88-
89-
github_id = github_response['id']
84+
85+
github_id = github_response["id"]
9086
print("UserID: ", github_id)
91-
92-
github_username = github_response['name']
87+
88+
github_username = github_response["name"]
9389
print("Username: ", github_username)
94-
95-
github_followers = github_response['followers']
90+
91+
github_followers = github_response["followers"]
9692
print("Followers: ", github_followers)
97-
93+
9894
print("Monotonic: ", time.monotonic())
9995

10096
print("\nFinished!")
10197
print("Next Update in %s %s" % (int(sleep_int), sleep_time_conversion))
10298
print("===============================")
10399
gc.collect()
104-
# pylint: disable=broad-except
100+
105101
except (ValueError, RuntimeError) as e:
106102
print("Failed to get data, retrying\n", e)
107103
time.sleep(60)

examples/requests_api_twitter.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# SPDX-FileCopyrightText: 2022 DJDevon3
1+
# SPDX-FileCopyrightText: 2022 DJDevon3 for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33
# Coded for Circuit Python 8.0
44
"""DJDevon3 Adafruit Feather ESP32-S2 Twitter_API_Example"""
5-
# pylint: disable=line-too-long
65
import gc
76
import time
87
import ssl
@@ -12,7 +11,7 @@
1211
import adafruit_requests
1312

1413
# Twitter developer account bearer token required.
15-
# Ensure these are uncommented and in secrets.py or .env
14+
# Ensure these are uncommented and in secrets.py or .env
1615
# "TW_userid": "Your Twitter user id", # numerical id not username
1716
# "TW_bearer_token": "Your long API Bearer token",
1817

@@ -43,7 +42,7 @@
4342
sleep_time_conversion = "days"
4443

4544
# Used with any Twitter 0auth request.
46-
twitter_header = {'Authorization': 'Bearer ' + secrets["TW_bearer_token"]}
45+
twitter_header = {"Authorization": "Bearer " + secrets["TW_bearer_token"]}
4746
TW_SOURCE = (
4847
"https://api.twitter.com/2/users/"
4948
+ secrets["TW_userid"]
@@ -58,7 +57,7 @@
5857
requests = adafruit_requests.Session(pool, ssl.create_default_context())
5958
while not wifi.radio.ipv4_address:
6059
try:
61-
wifi.radio.connect(secrets['ssid'], secrets['password'])
60+
wifi.radio.connect(secrets["ssid"], secrets["password"])
6261
except ConnectionError as e:
6362
print("Connection Error:", e)
6463
print("Retrying in 10 seconds")
@@ -79,39 +78,39 @@
7978
except ConnectionError as e:
8079
print("Connection Error:", e)
8180
print("Retrying in 10 seconds")
82-
81+
8382
# Print Full JSON to Serial
8483
debug_response = False # Set true to see full response
8584
if debug_response:
8685
dump_object = json.dumps(tw_json)
8786
print("JSON Dump: ", dump_object)
88-
87+
8988
# Print to Serial
9089
tw_debug_keys = True # Set true to print Serial data
9190
if tw_debug_keys:
92-
93-
tw_userid = tw_json['data']['id']
91+
92+
tw_userid = tw_json["data"]["id"]
9493
print("User ID: ", tw_userid)
95-
96-
tw_username = tw_json['data']['name']
94+
95+
tw_username = tw_json["data"]["name"]
9796
print("Name: ", tw_username)
98-
99-
tw_join_date = tw_json['data']['created_at']
97+
98+
tw_join_date = tw_json["data"]["created_at"]
10099
print("Member Since: ", tw_join_date)
101-
102-
tw_tweets = tw_json['data']['public_metrics']['tweet_count']
100+
101+
tw_tweets = tw_json["data"]["public_metrics"]["tweet_count"]
103102
print("Tweets: ", tw_tweets)
104-
105-
tw_followers = tw_json['data']['public_metrics']['followers_count']
103+
104+
tw_followers = tw_json["data"]["public_metrics"]["followers_count"]
106105
print("Followers: ", tw_followers)
107-
106+
108107
print("Monotonic: ", time.monotonic())
109108

110109
print("\nFinished!")
111110
print("Next Update in %s %s" % (int(sleep_int), sleep_time_conversion))
112111
print("===============================")
113112
gc.collect()
114-
# pylint: disable=broad-except
113+
115114
except (ValueError, RuntimeError) as e:
116115
print("Failed to get data, retrying\n", e)
117116
time.sleep(60)

examples/requests_api_youtube.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# SPDX-FileCopyrightText: 2022 DJDevon3
1+
# SPDX-FileCopyrightText: 2022 DJDevon3 for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33
# Coded for Circuit Python 8.0
44
"""DJDevon3 Adafruit Feather ESP32-S2 YouTube_API_Example"""
5-
# pylint: disable=line-too-long
65
import gc
76
import time
87
import ssl
@@ -11,7 +10,7 @@
1110
import socketpool
1211
import adafruit_requests
1312

14-
# Ensure these are uncommented and in secrets.py or .env
13+
# Ensure these are uncommented and in secrets.py or .env
1514
# "YT_username": "Your YouTube Username",
1615
# "YT_token" : "Your long API developer token",
1716

@@ -57,7 +56,7 @@
5756
requests = adafruit_requests.Session(pool, ssl.create_default_context())
5857
while not wifi.radio.ipv4_address:
5958
try:
60-
wifi.radio.connect(secrets['ssid'], secrets['password'])
59+
wifi.radio.connect(secrets["ssid"], secrets["password"])
6160
except ConnectionError as e:
6261
print("Connection Error:", e)
6362
print("Retrying in 10 seconds")
@@ -87,32 +86,32 @@
8786
# Print to Serial
8887
yt_debug_keys = True # Set to True to print Serial data
8988
if yt_debug_keys:
90-
print("Matching Results: ", response['pageInfo']['totalResults'])
89+
print("Matching Results: ", response["pageInfo"]["totalResults"])
9190

92-
YT_request_kind = response['items'][0]['kind']
91+
YT_request_kind = response["items"][0]["kind"]
9392
print("Request Kind: ", YT_request_kind)
94-
95-
YT_response_kind = response['kind']
93+
94+
YT_response_kind = response["kind"]
9695
print("Response Kind: ", YT_response_kind)
9796

98-
YT_channel_id = response['items'][0]['id']
97+
YT_channel_id = response["items"][0]["id"]
9998
print("Channel ID: ", YT_channel_id)
10099

101-
YT_videoCount = response['items'][0]['statistics']['videoCount']
100+
YT_videoCount = response["items"][0]["statistics"]["videoCount"]
102101
print("Videos: ", YT_videoCount)
103102

104-
YT_viewCount = response['items'][0]['statistics']['viewCount']
103+
YT_viewCount = response["items"][0]["statistics"]["viewCount"]
105104
print("Views: ", YT_viewCount)
106105

107-
YT_subsCount = response['items'][0]['statistics']['subscriberCount']
106+
YT_subsCount = response["items"][0]["statistics"]["subscriberCount"]
108107
print("Subscribers: ", YT_subsCount)
109108
print("Monotonic: ", time.monotonic())
110109

111110
print("\nFinished!")
112111
print("Next Update in %s %s" % (int(sleep_int), sleep_time_conversion))
113112
print("===============================")
114113
gc.collect()
115-
# pylint: disable=broad-except
114+
116115
except (ValueError, RuntimeError) as e:
117116
print("Failed to get data, retrying\n", e)
118117
time.sleep(60)

0 commit comments

Comments
 (0)