Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
918 commits
Select commit Hold shift + click to select a range
803d642
updated logs
actions-user Jun 27, 2024
25bbc43
updated logs
actions-user Jun 27, 2024
06c1763
updated logs
actions-user Jun 27, 2024
ef04a57
updated logs
actions-user Jun 27, 2024
6675cee
updated logs
actions-user Jun 28, 2024
818b76a
updated logs
actions-user Jun 28, 2024
0db3ca0
updated logs
actions-user Jun 28, 2024
0560924
updated logs
actions-user Jun 28, 2024
d467756
updated logs
actions-user Jun 28, 2024
635c622
Update main.py to add output into csv
swapnanilsharma Jun 28, 2024
36a997d
Merge pull request #1 from swapnanilsharma/add-csv
swapnanilsharma Jun 28, 2024
9a5bc1b
Update main.py
swapnanilsharma Jun 28, 2024
a2135c0
updated logs
actions-user Jun 28, 2024
6391ff3
pylint main.py
swapnanilsharma Jun 28, 2024
276e536
updated logs
actions-user Jun 28, 2024
1b8abfc
updated logs
actions-user Jun 28, 2024
4b2e741
updated logs
actions-user Jun 28, 2024
8cc6de9
updated logs
actions-user Jun 28, 2024
8a46e42
updated logs
actions-user Jun 28, 2024
2f8aaab
updated logs
actions-user Jun 28, 2024
42f53ba
updated logs
actions-user Jun 29, 2024
2e812d8
updated logs
actions-user Jun 29, 2024
84ed42e
updated logs
actions-user Jun 29, 2024
8802305
updated logs
actions-user Jun 29, 2024
89a3080
updated logs
actions-user Jun 29, 2024
9377c8a
updated logs
actions-user Jun 29, 2024
4e762a2
updated logs
actions-user Jun 29, 2024
1b41128
updated logs
actions-user Jun 29, 2024
f8a154a
updated logs
actions-user Jun 29, 2024
901356e
updated logs
actions-user Jun 29, 2024
6440143
updated logs
actions-user Jun 29, 2024
0fe07dc
updated logs
actions-user Jun 29, 2024
b9ac8af
updated logs
actions-user Jun 30, 2024
cfa474a
updated logs
actions-user Jun 30, 2024
3a4e605
updated logs
actions-user Jun 30, 2024
5bd4baf
updated logs
actions-user Jun 30, 2024
14e0068
updated logs
actions-user Jun 30, 2024
b072dff
updated logs
actions-user Jun 30, 2024
9c25ba3
updated logs
actions-user Jun 30, 2024
27c4edb
updated logs
actions-user Jun 30, 2024
ba39d4a
updated logs
actions-user Jun 30, 2024
ecfcf79
updated logs
actions-user Jun 30, 2024
51c911e
updated logs
actions-user Jun 30, 2024
c7dddcf
updated logs
actions-user Jun 30, 2024
d81a6c8
updated logs
actions-user Jul 1, 2024
33e187f
updated logs
actions-user Jul 1, 2024
5630028
updated logs
actions-user Jul 1, 2024
92ef078
updated logs
actions-user Jul 1, 2024
0833c50
updated logs
actions-user Jul 1, 2024
949c46a
updated logs
actions-user Jul 1, 2024
d02adcd
updated logs
actions-user Jul 1, 2024
a01a1f6
updated logs
actions-user Jul 1, 2024
2d5f20a
updated logs
actions-user Jul 1, 2024
4574179
updated logs
actions-user Jul 1, 2024
20228b8
updated logs
actions-user Jul 1, 2024
8108fbd
updated logs
actions-user Jul 1, 2024
eee71f8
updated logs
actions-user Jul 2, 2024
d3d0b44
updated logs
actions-user Jul 2, 2024
d03f699
updated logs
actions-user Jul 2, 2024
738a2db
updated logs
actions-user Jul 2, 2024
10958e6
updated logs
actions-user Jul 2, 2024
622d070
updated logs
actions-user Jul 2, 2024
6824543
updated logs
actions-user Jul 2, 2024
bb75bf8
updated logs
actions-user Jul 2, 2024
74bc4f3
updated logs
actions-user Jul 2, 2024
c0694d3
updated logs
actions-user Jul 2, 2024
8991c72
updated logs
actions-user Jul 2, 2024
616cb59
updated logs
actions-user Jul 2, 2024
491a59a
updated logs
actions-user Jul 3, 2024
a014946
updated logs
actions-user Jul 3, 2024
3b22d9b
updated logs
actions-user Jul 3, 2024
ff3db74
updated logs
actions-user Jul 3, 2024
eb766c6
updated logs
actions-user Jul 3, 2024
5104e0a
updated logs
actions-user Jul 3, 2024
8ff4cac
updated logs
actions-user Jul 3, 2024
369b876
updated logs
actions-user Jul 3, 2024
f4c72e9
updated logs
actions-user Jul 3, 2024
d6542c2
updated logs
actions-user Jul 3, 2024
6529652
updated logs
actions-user Jul 3, 2024
11e0a8d
updated logs
actions-user Jul 3, 2024
659db03
updated logs
actions-user Jul 4, 2024
1f04283
updated logs
actions-user Jul 4, 2024
29098ee
updated logs
actions-user Jul 4, 2024
6c03015
updated logs
actions-user Jul 4, 2024
8932bbf
updated logs
actions-user Jul 4, 2024
1e7c724
updated logs
actions-user Jul 4, 2024
4b903b1
updated logs
actions-user Jul 4, 2024
6d4f9e5
updated logs
actions-user Jul 4, 2024
fc2f059
updated logs
actions-user Jul 4, 2024
ba3f463
updated logs
actions-user Jul 4, 2024
f1f2657
updated logs
actions-user Jul 4, 2024
72f58ba
updated logs
actions-user Jul 4, 2024
ce0eab1
updated logs
actions-user Jul 5, 2024
315b189
updated logs
actions-user Jul 5, 2024
2ca7579
updated logs
actions-user Jul 5, 2024
ff8bf78
updated logs
actions-user Jul 5, 2024
f817e97
updated logs
actions-user Jul 5, 2024
bcbba09
updated logs
actions-user Jul 5, 2024
6daac19
updated logs
actions-user Jul 5, 2024
8a7b286
updated logs
actions-user Jul 5, 2024
99e188e
updated logs
actions-user Jul 5, 2024
fc7f7cd
updated logs
actions-user Jul 5, 2024
e3faee4
updated logs
actions-user Jul 5, 2024
a80916a
updated logs
actions-user Jul 5, 2024
f4dd818
updated logs
actions-user Jul 6, 2024
fddf8dd
updated logs
actions-user Jul 6, 2024
19184cc
updated logs
actions-user Jul 6, 2024
0ff511e
updated logs
actions-user Jul 6, 2024
d13ad7c
updated logs
actions-user Jul 6, 2024
5cb26d4
updated logs
actions-user Jul 6, 2024
9ab0638
updated logs
actions-user Jul 6, 2024
e9b2366
updated logs
actions-user Jul 6, 2024
72ff5f0
updated logs
actions-user Jul 6, 2024
bc63885
updated logs
actions-user Jul 6, 2024
d8c1997
updated logs
actions-user Jul 6, 2024
8dee5cd
updated logs
actions-user Jul 6, 2024
3322aa3
updated logs
actions-user Jul 7, 2024
931ef4a
updated logs
actions-user Jul 7, 2024
c446beb
updated logs
actions-user Jul 7, 2024
38028c4
updated logs
actions-user Jul 7, 2024
77ceadb
updated logs
actions-user Jul 7, 2024
70489e3
updated logs
actions-user Jul 7, 2024
e6b74dc
updated logs
actions-user Jul 7, 2024
46d06e7
updated logs
actions-user Jul 7, 2024
ccb9bea
updated logs
actions-user Jul 7, 2024
992fdfe
updated logs
actions-user Jul 7, 2024
177cd31
updated logs
actions-user Jul 7, 2024
c74173b
updated logs
actions-user Jul 7, 2024
12d66f2
updated logs
actions-user Jul 8, 2024
e7200c7
updated logs
actions-user Jul 8, 2024
8a69bc5
updated logs
actions-user Jul 8, 2024
a13b0e3
updated logs
actions-user Jul 8, 2024
3a0a522
updated logs
actions-user Jul 8, 2024
7ae7a8b
updated logs
actions-user Jul 8, 2024
f6ad660
updated logs
actions-user Jul 8, 2024
b88a151
updated logs
actions-user Jul 8, 2024
120f09c
updated logs
actions-user Jul 8, 2024
59dd17e
updated logs
actions-user Jul 8, 2024
a76809a
updated logs
actions-user Jul 8, 2024
4e40dd3
updated logs
actions-user Jul 8, 2024
609bee5
updated logs
actions-user Jul 9, 2024
fd093c6
updated logs
actions-user Jul 9, 2024
70718ee
updated logs
actions-user Jul 9, 2024
7753582
updated logs
actions-user Jul 9, 2024
c8f6fa1
updated logs
actions-user Jul 9, 2024
13e4e63
updated logs
actions-user Jul 9, 2024
b4c81f6
updated logs
actions-user Jul 9, 2024
5d54f32
updated logs
actions-user Jul 9, 2024
59173cc
updated logs
actions-user Jul 9, 2024
3d94907
updated logs
actions-user Jul 9, 2024
a2c5aac
updated logs
actions-user Jul 9, 2024
283be87
updated logs
actions-user Jul 9, 2024
11b2d08
updated logs
actions-user Jul 10, 2024
3a719d1
updated logs
actions-user Jul 10, 2024
33143c3
updated logs
actions-user Jul 10, 2024
409349b
updated logs
actions-user Jul 10, 2024
6e71ed3
updated logs
actions-user Jul 10, 2024
847a383
updated logs
actions-user Jul 10, 2024
892df3b
updated logs
actions-user Jul 10, 2024
d51e1b2
updated logs
actions-user Jul 10, 2024
e6b58f9
updated logs
actions-user Jul 10, 2024
ca6d361
updated logs
actions-user Jul 10, 2024
efc36e1
updated logs
actions-user Jul 10, 2024
2505ea6
updated logs
actions-user Jul 10, 2024
068470b
updated logs
actions-user Jul 11, 2024
ba71bb5
updated logs
actions-user Jul 11, 2024
4486142
updated logs
actions-user Jul 11, 2024
c53dd86
updated logs
actions-user Jul 11, 2024
04f0e23
updated logs
actions-user Jul 11, 2024
9582c91
updated logs
actions-user Jul 11, 2024
2ddcc01
updated logs
actions-user Jul 11, 2024
c82f097
updated logs
actions-user Jul 11, 2024
09ff567
updated logs
actions-user Jul 11, 2024
9b53f60
updated logs
actions-user Jul 11, 2024
db30340
updated logs
actions-user Jul 11, 2024
f99a907
updated logs
actions-user Jul 11, 2024
cb8f4ec
updated logs
actions-user Jul 12, 2024
e6129c4
updated logs
actions-user Jul 12, 2024
5ed4bd6
updated logs
actions-user Jul 12, 2024
1cabd4d
updated logs
actions-user Jul 12, 2024
6d254a9
updated logs
actions-user Jul 12, 2024
bed4b0a
updated logs
actions-user Jul 12, 2024
2febf20
updated logs
actions-user Jul 12, 2024
4e52d6a
updated logs
actions-user Jul 12, 2024
387454d
updated logs
actions-user Jul 12, 2024
664a5c9
updated logs
actions-user Jul 12, 2024
46e5701
updated logs
actions-user Jul 12, 2024
8856fdb
updated logs
actions-user Jul 12, 2024
ea7bc98
updated logs
actions-user Jul 13, 2024
8cbc70b
updated logs
actions-user Jul 13, 2024
ed4430e
updated logs
actions-user Jul 13, 2024
87fbf57
updated logs
actions-user Jul 13, 2024
be99540
updated logs
actions-user Jul 13, 2024
7a0bd35
updated logs
actions-user Jul 13, 2024
57d3c86
updated logs
actions-user Jul 13, 2024
8057984
updated logs
actions-user Jul 13, 2024
cef5946
updated logs
actions-user Jul 13, 2024
4d3e3c2
updated logs
actions-user Jul 13, 2024
e017452
updated logs
actions-user Jul 13, 2024
7678de1
updated logs
actions-user Jul 13, 2024
414e8ac
updated logs
actions-user Jul 14, 2024
212c5f7
updated logs
actions-user Jul 14, 2024
9050f90
updated logs
actions-user Jul 14, 2024
a7e26af
updated logs
actions-user Jul 14, 2024
00cbe52
updated logs
actions-user Jul 14, 2024
41b9edf
updated logs
actions-user Jul 14, 2024
957d354
updated logs
actions-user Jul 14, 2024
83b65b4
updated logs
actions-user Jul 14, 2024
41730e5
updated logs
actions-user Jul 14, 2024
6446a04
updated logs
actions-user Jul 14, 2024
b74ecf7
updated logs
actions-user Jul 14, 2024
cfd206a
updated logs
actions-user Jul 14, 2024
451fb0f
updated logs
actions-user Jul 15, 2024
5098643
updated logs
actions-user Jul 15, 2024
29597da
updated logs
actions-user Jul 15, 2024
4551fb6
updated logs
actions-user Jul 15, 2024
36fbe74
updated logs
actions-user Jul 15, 2024
b274e1d
updated logs
actions-user Jul 15, 2024
376a7a0
updated logs
actions-user Jul 15, 2024
71ecba3
updated logs
actions-user Jul 15, 2024
564fdd9
updated logs
actions-user Jul 15, 2024
dfd079e
updated logs
actions-user Jul 15, 2024
7aed014
updated logs
actions-user Jul 15, 2024
adb5815
updated logs
actions-user Jul 15, 2024
e9fdd11
updated logs
actions-user Jul 16, 2024
cc5e666
updated logs
actions-user Jul 16, 2024
f252c2d
updated logs
actions-user Jul 16, 2024
98409b5
updated logs
actions-user Jul 16, 2024
6145818
updated logs
actions-user Jul 16, 2024
f6824c8
updated logs
actions-user Jul 16, 2024
bb8325a
updated logs
actions-user Jul 16, 2024
4401c8d
updated logs
actions-user Jul 16, 2024
2e6d123
updated logs
actions-user Jul 16, 2024
9ae3965
updated logs
actions-user Jul 16, 2024
f079088
updated logs
actions-user Jul 16, 2024
906dbf6
updated logs
actions-user Jul 16, 2024
2bfb312
updated logs
actions-user Jul 17, 2024
d843a01
updated logs
actions-user Jul 17, 2024
813296a
updated logs
actions-user Jul 17, 2024
2ba1b10
updated logs
actions-user Jul 17, 2024
4a77186
updated logs
actions-user Jul 17, 2024
ce5f6f8
updated logs
actions-user Jul 17, 2024
48bab00
updated logs
actions-user Jul 17, 2024
f8539c3
updated logs
actions-user Jul 17, 2024
2db812f
updated logs
actions-user Jul 17, 2024
eec9fbb
commit optimised code
swapnanilsharma Jul 17, 2024
a0bc97f
pylint fix
swapnanilsharma Jul 17, 2024
c2aaa46
remove extra code
swapnanilsharma Jul 17, 2024
0b504cb
remove unused variable
swapnanilsharma Jul 17, 2024
d61ec8c
add code to read secret
swapnanilsharma Jul 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: run main.py

on:
schedule:
- cron: '0 0 * * 1' # At 00:00 on Monday
- cron: '0 */2 * * *' # Every 2 hours

jobs:
build:
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Pylint

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
pip install -r requirements.txt
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
99 changes: 75 additions & 24 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,85 @@
"""
Retrieve weather data for a given city and log it.
"""

import csv
import logging
import logging.handlers
from datetime import datetime
from typing import Optional
import os

import pytz
import requests

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger_file_handler = logging.handlers.RotatingFileHandler(
"status.log",
maxBytes=1024 * 1024,
backupCount=1,
encoding="utf8",
)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
logger_file_handler.setFormatter(formatter)
logger.addHandler(logger_file_handler)

try:
SOME_SECRET = os.environ["SOME_SECRET"]
except KeyError:
SOME_SECRET = "Token not available!"
#logger.info("Token not available!")
#raise
logger.addHandler(logging.StreamHandler())


if __name__ == "__main__":
logger.info(f"Token value: {SOME_SECRET}")
def get_weather_data(city: str) -> Optional[dict]:
"""
Get weather data for the given city from the Talk Python Weather API.

:param city: The city for which to get the weather data.
:return: A dictionary containing the weather data or None if the request failed.
"""
api_url = "https://weather.talkpython.fm/api/weather/"
params = {"city": city, "country": "IN"}
try:
response = requests.get(api_url, params=params, timeout=10)
return response.json() if response.status_code == 200 else None
except (requests.Timeout, requests.RequestException):
return None


def log_weather_data(city: str, data: dict) -> None:
"""
Log the weather data for a given city.

:param city: The city for which the weather data is logged.
:param data: The weather data to be logged.
"""
logger.info("City: %s", city)
logger.info("Temperature: %s", data.get("forecast", {}).get("temp"))
logger.info("Feels Like: %s", data.get("forecast", {}).get("feels_like"))
logger.info("Humidity: %s", data.get("forecast", {}).get("humidity"))

utc_now = datetime.utcnow()
ist_now = utc_now.astimezone(pytz.timezone("Asia/Kolkata"))

logger.info("Current IST time: %s", ist_now.strftime("%Y-%m-%d %H:%M:%S"))

r = requests.get('https://weather.talkpython.fm/api/weather/?city=Berlin&country=DE')
if r.status_code == 200:
data = r.json()
temperature = data["forecast"]["temp"]
logger.info(f'Weather in Berlin: {temperature}')
with open("weather_data.csv", mode="a", newline="", encoding="utf-8") as file:
writer = csv.writer(file)
if file.tell() == 0:
writer.writerow(["Timestamp", "Temperature", "Feels Like", "Humidity"])
writer.writerow(
[
ist_now.strftime("%Y-%m-%d %H:%M:%S"),
data.get("forecast", {}).get("temp"),
data.get("forecast", {}).get("feels_like"),
data.get("forecast", {}).get("humidity"),
]
)


def main() -> None:
"""
The main function for this module.
"""
token = os.environ.get("SOME_SECRET")
if token is None:
logger.error("Token value is not available.")
return

city = "Pune"
data = get_weather_data(city)
if data is None:
logger.error("Failed to get weather data for %s.", city)
return

log_weather_data(city, data)


if __name__ == "__main__":
main()
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
requests==2.28.1
requests==2.31.0
pytz
Loading