Skip to content

Commit 75d427c

Browse files
committed
- Docker files
1 parent 604c5ed commit 75d427c

5 files changed

+48
-34
lines changed

General.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import json
33

44
class misc_functions():
5-
#reading data from JSON file
5+
"""#reading data from JSON fil"""
66
@staticmethod
77
def get_data_from_json() -> dict:
88
print('Getting data from JSON...')

TwitterIntegration.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,21 @@ async def prepare_twitter(city_data: dict, *,config_json:dict) -> str:
3939
temp_act=city_data['temp_act'],
4040
humidity=city_data['humidity'],
4141
pressure=city_data['pressure'],
42-
city=city_data['city_name']
42+
city_hash=city_data['city_name'].replace(" ","")
4343
)
4444
return twitter_body
4545

4646
@staticmethod
4747
async def create_twitter(*,client: object, twitter_body: str) -> None:
4848
"""Post to twitter"""
4949
try:
50-
client.twitter(text=twitter_body)
51-
print('Twitter posted...')
50+
client.create_tweet(text=twitter_body)
51+
print(f'Twitter posted...')
5252
except tweepy.errors.BadRequest as e:
5353
print(f'Error while posting tweet -> \n {twitter_body}\n {e.response.status_code}...')
5454
except tweepy.errors.TooManyRequests as e:
5555
print(f'Error while posting tweet -> \n {twitter_body}\n {e.response.status_code}...')
56+
except tweepy.errors.Forbidden as e:
57+
print(f'Error while posting tweet -> \n {twitter_body}\n {e.response.status_code}...')
58+
except SystemError as e:
59+
print(f'Error while posting tweet -> \n {twitter_body}\n {e.response.status_code}...')

WeatherManagment.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#Get data from open weather, return data to post on twitter
22
import requests
3-
import json
4-
import asyncio
53
import aiohttp
64

75

@@ -43,6 +41,7 @@ async def call_api(session: aiohttp.ClientSession,city:str, api_key:str):
4341
if response.status == 404:
4442
print(f'Status -> {response.status}')
4543
raise requests.HTTPError(response.status)
44+
4645
return await response.json()
4746
except Exception as e:
4847
print(f'Error with URL {response.url}, error -> {e}')
@@ -51,7 +50,14 @@ async def call_api(session: aiohttp.ClientSession,city:str, api_key:str):
5150
async def prepare_data(city_json: dict) -> dict:
5251
"""Prepare data for further processing"""
5352
city_data: dict = {}
54-
city_data['city_name'] = city_json['name']
53+
54+
if city_json['name'] == 'Województwo opolskie':
55+
city_data['city_name'] = 'Opole'
56+
elif city_json['name'] == 'Województwo lubelskie':
57+
city_data['city_name'] = 'Lublin'
58+
else:
59+
city_data['city_name'] = city_json['name']
60+
5561
city_data['weather_dsc'] = city_json['weather'][0]['description']
5662
city_data['temp_min'] = city_json['main']['temp_min']
5763
city_data['temp_max'] = city_json['main']['temp_max']

config.json

+27-24
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
{
2-
3-
4-
"cityList": [
5-
"Kielce",
6-
"Wrocław",
7-
"Bydgoszcz",
8-
"Toruń",
9-
"Lublin",
10-
"Gorzów Wielkopolski",
11-
"Zielona Góra",
12-
"Łódź",
13-
"Kraków",
14-
"Warszawa",
15-
"Opole",
16-
"Rzeszów",
17-
"Białystok",
18-
"Gdańsk",
19-
"Katowice",
20-
"Kielce",
21-
"Olsztyn",
22-
"Poznań",
23-
"Szczecin"
24-
]
25-
2+
"apiKeyTweeter":"",
3+
"apiSecretTweeter":"",
4+
"bearerTokenTweeter":"",
5+
"accessTokenTweeter":"",
6+
"accessTokenSecretTweeter":"",
7+
"apiKeyOpenWeather": "",
8+
"city_list": [
9+
"Białystok",
10+
"Bydgoszcz",
11+
"Gdańsk",
12+
"Gorzów Wielkopolski",
13+
"Katowice",
14+
"Kielce",
15+
"Kraków",
16+
"Lublin",
17+
"Łódź",
18+
"Olsztyn",
19+
"Opole",
20+
"Poznań",
21+
"Rzeszów",
22+
"Szczecin",
23+
"Toruń",
24+
"Warszawa",
25+
"Wrocław",
26+
"Zielona Góra"
27+
],
28+
"twitter_template": "Miasto: {city_name}\nPogoda: {weather_dsc}\nTemperatura: {temp_act} C\nWilgotność: {humidity}%\nCiśnienie: {pressure}hPa\n#Polska #{city_hash} #Pogoda"
2629
}
2730

main.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ async def main() -> None:
3939
print('Preparing bodies for twitter...')
4040
tasks: list[dict] = [twitter.prepare_twitter(desc, config_json=config_json) for desc in processing_data]
4141
twitter_bodies = await asyncio.gather(*tasks)
42+
#print(twitter_bodies)
4243

4344
#Post to twitter
4445
print('Preparing bodies for twitter...')
45-
for item in twitter_bodies:
46-
print('-----')
47-
print(item)
46+
#for item in twitter_bodies:
47+
# print('-----')
48+
# print(item)
4849

4950
tasks: list[dict] = [twitter.create_twitter(client=client,twitter_body=body) for body in twitter_bodies]
5051
asyncio.gather(*tasks)

0 commit comments

Comments
 (0)