-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathrss_parser.py
More file actions
1655 lines (1378 loc) · 70.7 KB
/
rss_parser.py
File metadata and controls
1655 lines (1378 loc) · 70.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# rss_parser.py
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# github.com/FlyingFathead/TelegramBot-OpenAI-API/
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from datetime import datetime, timezone
from dateutil import parser as date_parser
from bs4 import BeautifulSoup
import feedparser
import requests
import sys
import os
import json
import logging
import traceback
import pytz
import subprocess
import re
import time
import threading
import shutil
# Set default values for max days old and max entries to display
DEFAULT_MAX_DAYS_OLD = 7
DEFAULT_MAX_ENTRIES = 20
# Configure logging
logging.basicConfig(level=logging.INFO, format='[%(levelname)s] %(message)s')
# print term width horizontal line
def print_horizontal_line(character='-'):
terminal_width = shutil.get_terminal_size().columns
line = character * terminal_width
logging.info(line)
# Get the time since publication
def get_time_elapsed(published_time):
current_time = datetime.now(pytz.UTC)
time_difference = current_time - published_time
minutes = int(time_difference.total_seconds() // 60)
if minutes < 60:
return f"{minutes}m"
elif minutes < 1440: # Less than a day
hours = minutes // 60
return f"{hours}h"
else:
days = minutes // 1440
return f"{days}d"
# # get the time since publication
# def get_time_elapsed(published_time):
# current_time = datetime.now(pytz.UTC)
# time_difference = current_time - published_time
# minutes = int(time_difference.total_seconds() // 60)
# if minutes < 60:
# return f"{minutes}m"
# else:
# hours = minutes // 60
# return f"{hours}h"
#
# ))> weather
#
def get_foreca_dump():
logging.info('Getting data dump from Foreca.')
# Set the regular expressions to match and extract content
remove_everything_until = r'Suomen sää juuri nyt'
remove_everything_after = r'MTV Sää'
# Execute the lynx command and capture the output
command = ['lynx', '--dump', '-nolist', 'https://www.foreca.fi/']
output = subprocess.check_output(command, universal_newlines=True)
# Trim the output based on the specified regular expressions
trimmed_output = re.search(
rf'{remove_everything_until}(.*?){remove_everything_after}',
output,
re.DOTALL
)
# Print the trimmed output if markers are found
if trimmed_output:
print_horizontal_line()
logging.info(trimmed_output.group(1))
print_horizontal_line()
return trimmed_output.group(1)
else:
error_message = "[ERROR!] Start or stop marker not found in the output."
logging.error(error_message)
return error_message
def get_weather(city):
logging.info('Getting `ansiweather` weather.')
result = subprocess.run(['ansiweather', '-l', city, '-d', 'true', '-H', 'true'], capture_output=True, text=True)
output = result.stdout.strip()
# Remove ANSI escape sequences
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
output = ansi_escape.sub('', output)
return output
#
# ))> news sources
#
def get_most_read():
if os.path.isfile('data_uutiset.txt'):
with open('data_uutiset.txt', 'r') as file:
return file.read()
else:
return ""
#
# ))> bbc
#
# bbc.co.uk // top stories
def get_bbc_business(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
try:
# Fetch the RSS feed
response = requests.get('http://feeds.bbci.co.uk/news/business/rss.xml')
# Parse the RSS feed
feed = feedparser.parse(response.content)
# Extract the headlines, descriptions, links, and pubDates
items = [{'title': entry.title, 'description': entry.description, 'link': entry.link, 'pubDate': entry.published}
for entry in feed.entries]
# Filter and format the items with titles, descriptions, and elapsed time
formatted_items = []
current_time = datetime.now(pytz.UTC)
for item in items:
pub_date = datetime.strptime(item['pubDate'], "%a, %d %b %Y %H:%M:%S GMT")
pub_date = pub_date.replace(tzinfo=pytz.timezone('GMT'))
if (current_time - pub_date).days <= max_days_old:
time_elapsed = get_time_elapsed(pub_date)
formatted_item = f'<p><i>({time_elapsed})</i> <a href="{item["link"]}">{item["title"]}</a>: {item["description"]}</p>'
formatted_items.append(formatted_item)
if len(formatted_items) >= max_entries:
break
# Join the formatted items into a string with each item on a new line
items_string = '\n'.join(formatted_items)
items_string_out = 'Latest business news from bbc.co.uk (BBC News Business):\n\n' + items_string
print_horizontal_line()
logging.info(items_string_out)
print_horizontal_line()
return {
'type': 'text',
'content': items_string_out,
'html': f'<ul>{items_string_out}</ul>'
}
except Exception as e:
logging.error(f"Error fetching bbc.co.uk news: {e}")
return {
'type': 'text',
'content': "Sori! En päässyt käsiksi bbc.co.uk:n uutisvirtaan. Mönkään meni! Pahoitteluni!",
'html': "Sori! En päässyt käsiksi bbc.co.uk:n uutisvirtaan. Mönkään meni! Pahoitteluni!"
}
# bbc // science & environment
def get_bbc_science_environment(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
try:
# Fetch the RSS feed
response = requests.get('http://feeds.bbci.co.uk/news/science_and_environment/rss.xml')
# Parse the RSS feed
feed = feedparser.parse(response.content)
# Extract the headlines, descriptions, links, and pubDates
items = [{'title': entry.title, 'description': entry.description, 'link': entry.link, 'pubDate': entry.published}
for entry in feed.entries]
# Filter and format the items with titles, descriptions, and elapsed time
formatted_items = []
current_time = datetime.now(pytz.UTC)
for item in items:
pub_date = datetime.strptime(item['pubDate'], "%a, %d %b %Y %H:%M:%S GMT")
pub_date = pub_date.replace(tzinfo=pytz.timezone('GMT'))
if (current_time - pub_date).days <= max_days_old:
formatted_date = pub_date.strftime("%b %d")
formatted_item = f'<p><i>({formatted_date})</i> <a href="{item["link"]}">{item["title"]}</a>: {item["description"]}</p>'
formatted_items.append(formatted_item)
if len(formatted_items) >= max_entries:
break
# Join the formatted items into a string with each item on a new line
items_string = '\n'.join(formatted_items)
items_string_out = 'Tässä bbc.co.uk:n tuoreimmat tiede- ja ympäristöuutiset.\n(BBC News: Science & Environment):\n\n' + items_string
print_horizontal_line()
logging.info(items_string_out)
print_horizontal_line()
return {
'type': 'text',
'content': items_string_out,
'html': f'<ul>{items_string_out}</ul>'
}
except Exception as e:
logging.error(f"Error fetching bbc.co.uk news: {e}")
return {
'type': 'text',
'content': "Sori! En päässyt käsiksi bbc.co.uk:n uutisvirtaan. Mönkään meni! Pahoitteluni!",
'html': "Sori! En päässyt käsiksi bbc.co.uk:n uutisvirtaan. Mönkään meni! Pahoitteluni!"
}
# bbc.co.uk // top stories
def get_bbc_top_stories(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
try:
# Fetch the RSS feed
response = requests.get('http://feeds.bbci.co.uk/news/rss.xml')
# Parse the RSS feed
feed = feedparser.parse(response.content)
# Extract the headlines, descriptions, links, and pubDates
items = [{'title': entry.title, 'description': entry.description, 'link': entry.link, 'pubDate': entry.published}
for entry in feed.entries]
# Filter and format the items with titles, descriptions, and elapsed time
formatted_items = []
current_time = datetime.now(pytz.UTC)
for item in items:
pub_date = datetime.strptime(item['pubDate'], "%a, %d %b %Y %H:%M:%S GMT")
pub_date = pub_date.replace(tzinfo=pytz.timezone('GMT'))
if (current_time - pub_date).days <= max_days_old:
time_elapsed = get_time_elapsed(pub_date)
formatted_item = f'<p><i>({time_elapsed})</i> <a href="{item["link"]}">{item["title"]}</a>: {item["description"]}</p>'
formatted_items.append(formatted_item)
if len(formatted_items) >= max_entries:
break
# Join the formatted items into a string with each item on a new line
items_string = '\n'.join(formatted_items)
items_string_out = 'Tässä BBC:n tämän hetken pääuutisaiheet (BBC News, bbc.co.uk):\n\n' + items_string
print_horizontal_line()
logging.info(items_string_out)
print_horizontal_line()
return {
'type': 'text',
'content': items_string_out,
'html': f'<ul>{items_string_out}</ul>'
}
except Exception as e:
logging.error(f"Error fetching bbc.co.uk news: {e}")
return {
'type': 'text',
'content': "Sori! En päässyt käsiksi bbc.co.uk:n uutisvirtaan. Mönkään meni! Pahoitteluni!",
'html': "Sori! En päässyt käsiksi bbc.co.uk:n uutisvirtaan. Mönkään meni! Pahoitteluni!"
}
#
# )> cnn.com
#
# cnn // U.S. News
# CNN news parsing
def get_cnn_us_news(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
try:
# Fetch the RSS feed
response = requests.get('http://rss.cnn.com/rss/edition_us.rss')
# Parse the RSS feed
feed = feedparser.parse(response.content)
# Check if there are any entries in the feed
if not feed.entries:
raise ValueError("The feed is empty")
# Format the items with titles and dates
formatted_items = []
current_time = datetime.now(pytz.UTC)
for entry in feed.entries:
# Skip if title and link are not available
if not all(hasattr(entry, attr) for attr in ['title', 'link']):
continue
title = entry.title
link = entry.link
if hasattr(entry, 'published'):
pub_date = datetime.strptime(entry.published, "%a, %d %b %Y %H:%M:%S %Z")
pub_date = pub_date.replace(tzinfo=pytz.UTC)
if (current_time - pub_date).days <= max_days_old:
formatted_date = pub_date.strftime("%b %d")
formatted_item = f'<p><i>({formatted_date})</i> <a href="{link}">{title}</a></p>'
formatted_items.append(formatted_item)
if len(formatted_items) >= max_entries:
break
# Join the formatted items into a string with each item on a new line
items_string = '\n'.join(formatted_items)
items_string_out = 'Tässä CNN:n (cnn.com) tuoreimmat uutiset USA:sta:\n\n' + items_string
print_horizontal_line()
logging.info(items_string_out)
print_horizontal_line()
return {
'type': 'text',
'content': items_string_out,
'html': f'<ul>{items_string_out}</ul>'
}
except Exception as e:
logging.error(f"Error fetching cnn.com news: {e}")
return {
'type': 'text',
'content': "Sori! En päässyt käsiksi cnn.com:in uutisvirtaan. Mönkään meni! Pahoitteluni!",
'html': "Sori! En päässyt käsiksi cnn.com:in uutisvirtaan. Mönkään meni! Pahoitteluni!"
}
# cnn // world edition
def get_cnn_world_edition(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
try:
# Fetch the RSS feed
response = requests.get('http://rss.cnn.com/rss/edition_world.rss')
# Parse the RSS feed
feed = feedparser.parse(response.content)
# Format the items with titles and dates
formatted_items = []
current_time = datetime.now(pytz.UTC)
for entry in feed.entries:
# Skip if title and link are not available
if not all(hasattr(entry, attr) for attr in ['title', 'link']):
continue
title = entry.title
link = entry.link
if hasattr(entry, 'published'):
pub_date = datetime.strptime(entry.published, "%a, %d %b %Y %H:%M:%S %Z")
pub_date = pub_date.replace(tzinfo=pytz.UTC)
if (current_time - pub_date).days <= max_days_old:
formatted_date = pub_date.strftime("%b %d")
formatted_item = f'<p><i>({formatted_date})</i> <a href="{link}">{title}</a></p>'
formatted_items.append(formatted_item)
else:
formatted_item = f'<p><a href="{link}">{title}</a></p>'
formatted_items.append(formatted_item)
if len(formatted_items) >= max_entries:
break
# Join the formatted items into a string with each item on a new line
items_string = '\n'.join(formatted_items)
items_string_out = 'Tässä CNN:n (cnn.com) uutiset maailmalta:\n\n' + items_string
print_horizontal_line()
logging.info(items_string_out)
print_horizontal_line()
return {
'type': 'text',
'content': items_string_out,
'html': f'<ul>{items_string_out}</ul>'
}
except Exception as e:
logging.error(f"Error fetching cnn.com news: {e}")
return {
'type': 'text',
'content': "Sori! En päässyt käsiksi cnn.com:in uutisvirtaan. Mönkään meni! Pahoitteluni!",
'html': "Sori! En päässyt käsiksi cnn.com:in uutisvirtaan. Mönkään meni! Pahoitteluni!"
}
#
# )> hs.fi
#
# hs.fi // etusivu
def get_hs_etusivu(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_hs_rss_feed('http://www.hs.fi/rss/teasers/etusivu.xml', 'etusivun uutiset', max_days_old, max_entries)
def get_hs_uusimmat(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_hs_rss_feed('http://www.hs.fi/rss/tuoreimmat.xml', 'uusimmat uutiset', max_days_old, max_entries)
def get_hs_kotimaa(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_hs_rss_feed('http://www.hs.fi/rss/suomi.xml', 'kotimaan uutiset', max_days_old, max_entries)
def get_hs_ulkomaat(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_hs_rss_feed('http://www.hs.fi/rss/maailma.xml', 'ulkomaan uutiset', max_days_old, max_entries)
def get_hs_talous(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_hs_rss_feed('http://www.hs.fi/rss/talous.xml', 'talousuutiset', max_days_old, max_entries)
def get_hs_politiikka(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_hs_rss_feed('http://www.hs.fi/rss/politiikka.xml', 'politiikan uutiset', max_days_old, max_entries)
def get_hs_helsinki(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_hs_rss_feed('http://www.hs.fi/rss/helsinki.xml', 'Helsingin uutiset', max_days_old, max_entries)
def get_hs_urheilu(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_hs_rss_feed('http://www.hs.fi/rss/urheilu.xml', 'urheilu-uutiset', max_days_old, max_entries)
def get_hs_kulttuuri(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_hs_rss_feed('http://www.hs.fi/rss/kulttuuri.xml', 'kulttuuriuutiset', max_days_old, max_entries)
def get_hs_paakirjoitukset(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_hs_rss_feed('http://www.hs.fi/rss/paakirjoitukset.xml', 'pääkirjoitukset', max_days_old, max_entries)
def get_hs_lastenuutiset(max_days_old=365, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_hs_rss_feed('http://www.hs.fi/rss/lastenuutiset.xml', 'lasten uutiset', max_days_old, max_entries)
def get_hs_ruoka(max_days_old=365, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_hs_rss_feed('http://www.hs.fi/rss/ruoka.xml', 'ruoka', max_days_old, max_entries)
def get_hs_elama(max_days_old=365, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_hs_rss_feed('http://www.hs.fi/rss/elama.xml', 'elämä', max_days_old, max_entries)
def get_hs_tiede(max_days_old=365, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_hs_rss_feed('http://www.hs.fi/rss/tiede.xml', 'tiedeuutiset', max_days_old, max_entries)
def get_hs_kuukausiliite(max_days_old=365, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_hs_rss_feed('http://www.hs.fi/rss/kuukausiliite.xml', 'kuukausiliite', max_days_old, max_entries)
# Fetch and process RSS feed for HS
def fetch_and_process_hs_rss_feed(url, category_name, max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
try:
# Ensure max_days_old and max_entries are integers
max_days_old = int(max_days_old)
max_entries = int(max_entries)
# Fetch the RSS feed
response = requests.get(url)
# Parse the RSS feed
feed = feedparser.parse(response.content)
# Define possible date formats
date_formats = ["%a, %d %b %Y %H:%M:%S %Z", "%a, %d %b %Y %H:%M:%S GMT"]
# Extract the headlines, descriptions, links, and pubDates
items = [{'title': entry.title,
'description': getattr(entry, 'description', None),
'link': entry.link,
'pubDate': entry.published}
for entry in feed.entries]
# Format the items with titles, descriptions (if available), and elapsed time
formatted_items = []
current_time = datetime.now(pytz.UTC)
for item in items:
pub_date = None
for date_format in date_formats:
try:
pub_date = datetime.strptime(item['pubDate'], date_format)
pub_date = pub_date.replace(tzinfo=pytz.UTC)
break
except ValueError:
continue
if pub_date is None:
logging.error(f"Failed to parse date: {item['pubDate']}")
continue
if (current_time - pub_date).days <= max_days_old:
time_elapsed = get_time_elapsed(pub_date)
if item['description']:
formatted_item = f'<p><i>({time_elapsed})</i> <a href="{item["link"]}">{item["title"]}</a>: {item["description"]}</p>'
else:
formatted_item = f'<p><i>({time_elapsed})</i> <a href="{item["link"]}">{item["title"]}</a></p>'
formatted_items.append(formatted_item)
if len(formatted_items) >= max_entries:
break
# Join the formatted items into a string with each item on a new line
items_string = '\n'.join(formatted_items)
items_string_out = f'Tässä hs.fi:n {category_name}:\n\n' + items_string
print_horizontal_line()
logging.info(items_string_out)
print_horizontal_line()
return {
'type': 'text',
'content': items_string_out,
'html': f'<ul>{items_string_out}</ul>'
}
except Exception as e:
logging.error(f"Error fetching hs.fi {category_name} news: {e}")
return {
'type': 'text',
'content': f"Sori! En päässyt käsiksi hs.fi:n {category_name}-uutisvirtaan. Mönkään meni! Pahoitteluni!",
'html': f"Sori! En päässyt käsiksi hs.fi:n {category_name}-uutisvirtaan. Mönkään meni! Pahoitteluni!"
}
#
# )> il.fi
#
# il.fi // uutiset
def get_il_uutiset(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
try:
# Fetch the RSS feed
response = requests.get('https://www.iltalehti.fi/rss/uutiset.xml')
# Parse the RSS feed
feed = feedparser.parse(response.content)
# Extract the headlines, descriptions, links, and pubDates
items = [{'title': entry.title, 'description': entry.description, 'link': entry.link, 'pubDate': entry.published}
for entry in feed.entries]
# Format the items with titles, descriptions, and elapsed time
formatted_items = []
current_time = datetime.now(pytz.UTC)
for item in items:
pub_date = datetime.strptime(item['pubDate'], "%a, %d %b %Y %H:%M:%S %z")
pub_date = pub_date.replace(tzinfo=pytz.UTC)
if (current_time - pub_date).days <= max_days_old:
time_elapsed = get_time_elapsed(pub_date)
formatted_item = f'<p><i>({time_elapsed})</i> <a href="{item["link"]}">{item["title"]}</a></p>'
formatted_items.append(formatted_item)
if len(formatted_items) >= max_entries:
break
# Join the formatted items into a string with each item on a new line
items_string = '\n'.join(formatted_items)
items_string_out = 'Tässä tuoreimmat uutiset <a href="https://is.fi/">il.fi</a>:stä:<br>' + items_string
print_horizontal_line()
logging.info(items_string_out)
print_horizontal_line()
return {
'type': 'text',
'content': items_string_out,
'html': f'<ul>{items_string_out}</ul>'
}
except Exception as e:
logging.error(f"Error fetching Iltasanomat news: {e}")
return {
'type': 'text',
'content': "Sori! En päässyt käsiksi il.fi:n uutisvirtaan. Mönkään meni! Pahoitteluni!",
'html': "Sori! En päässyt käsiksi il.fi:n uutisvirtaan. Mönkään meni! Pahoitteluni!"
}
# il.fi // urheilu
def get_il_urheilu(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
try:
# Fetch the RSS feed
response = requests.get('https://www.iltalehti.fi/rss/urheilu.xml')
# Parse the RSS feed
feed = feedparser.parse(response.content)
# Extract the headlines, descriptions, links, and pubDates
items = [{'title': entry.title, 'description': entry.description, 'link': entry.link, 'pubDate': entry.published}
for entry in feed.entries]
# Format the items with titles, descriptions, and elapsed time
formatted_items = []
current_time = datetime.now(pytz.UTC)
for item in items:
pub_date = datetime.strptime(item['pubDate'], "%a, %d %b %Y %H:%M:%S %z")
pub_date = pub_date.replace(tzinfo=pytz.UTC)
if (current_time - pub_date).days <= max_days_old:
time_elapsed = get_time_elapsed(pub_date)
formatted_item = f'<p><i>({time_elapsed})</i> <a href="{item["link"]}">{item["title"]}</a></p>'
formatted_items.append(formatted_item)
if len(formatted_items) >= max_entries:
break
# Join the formatted items into a string with each item on a new line
items_string = '\n'.join(formatted_items)
items_string_out = 'Tässä tuoreimmat urheilu-uutiset <a href="https://il.fi/">il.fi</a>:stä:\n\n' + items_string
print_horizontal_line()
logging.info(items_string_out)
print_horizontal_line()
return {
'type': 'text',
'content': items_string_out,
'html': f'<ul>{items_string_out}</ul>'
}
except Exception as e:
logging.error(f"Error fetching il.fi/urheilu news: {e}")
return {
'type': 'text',
'content': "Sori! En päässyt käsiksi il.fi:n uutisvirtaan. Mönkään meni! Pahoitteluni!",
'html': "Sori! En päässyt käsiksi il.fi:n uutisvirtaan. Mönkään meni! Pahoitteluni!"
}
#
# )> is.fi
#
# Fetch and process RSS feed for IS.fi
def fetch_and_process_is_rss_feed(url, category_name, max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
try:
# Ensure max_days_old and max_entries are integers
max_days_old = int(max_days_old)
max_entries = int(max_entries)
# Fetch the RSS feed
response = requests.get(url)
# Parse the RSS feed
feed = feedparser.parse(response.content)
# Define possible date formats
date_formats = ["%a, %d %b %Y %H:%M:%S %z", "%a, %d %b %Y %H:%M:%S %Z"]
# Extract the headlines, descriptions, links, and pubDates
items = [{'title': entry.title,
'description': getattr(entry, 'description', None),
'link': entry.link,
'pubDate': entry.published}
for entry in feed.entries]
# Format the items with titles, descriptions (if available), and elapsed time
formatted_items = []
current_time = datetime.now(pytz.UTC)
for item in items:
pub_date = None
for date_format in date_formats:
try:
pub_date = datetime.strptime(item['pubDate'], date_format)
pub_date = pub_date.replace(tzinfo=pytz.UTC)
break
except ValueError:
continue
if pub_date is None:
logging.error(f"Failed to parse date: {item['pubDate']}")
continue
if (current_time - pub_date).days <= max_days_old:
time_elapsed = get_time_elapsed(pub_date)
if item['description']:
formatted_item = f'<p><i>({time_elapsed})</i> <a href="{item["link"]}">{item["title"]}</a>: {item["description"]}</p>'
else:
formatted_item = f'<p><i>({time_elapsed})</i> <a href="{item["link"]}">{item["title"]}</a></p>'
formatted_items.append(formatted_item)
if len(formatted_items) >= max_entries:
break
# Join the formatted items into a string with each item on a new line
items_string = '\n'.join(formatted_items)
items_string_out = f'Tässä IS.fi:n {category_name}:\n\n' + items_string
print_horizontal_line()
logging.info(items_string_out)
print_horizontal_line()
return {
'type': 'text',
'content': items_string_out,
'html': f'<ul>{items_string_out}</ul>'
}
except Exception as e:
logging.error(f"Error fetching IS.fi {category_name} news: {e}")
return {
'type': 'text',
'content': f"Sori! En päässyt käsiksi IS.fi:n {category_name}-uutisvirtaan. Mönkään meni! Pahoitteluni!",
'html': f"Sori! En päässyt käsiksi IS.fi:n {category_name}-uutisvirtaan. Mönkään meni! Pahoitteluni!"
}
# is.fi // tuoreimmat uutiset
def get_is_tuoreimmat(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/tuoreimmat.xml', 'tuoreimmat uutiset', max_days_old, max_entries)
# is.fi // kotimaan uutiset
def get_is_kotimaa(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/kotimaa.xml', 'kotimaan uutiset', max_days_old, max_entries)
# is.fi // politiikka
def get_is_politiikka(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/politiikka.xml', 'politiikan uutiset', max_days_old, max_entries)
# is.fi // taloussanomat
def get_is_taloussanomat(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/taloussanomat.xml', 'taloussanomat', max_days_old, max_entries)
# is.fi // ulkomaat
def get_is_ulkomaat(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/ulkomaat.xml', 'ulkomaan uutiset', max_days_old, max_entries)
# is.fi // pääkirjoitus
def get_is_paakirjoitus(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/paakirjoitus.xml', 'pääkirjoitus', max_days_old, max_entries)
# is.fi // viihde
def get_is_viihde(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/viihde.xml', 'viihde', max_days_old, max_entries)
# is.fi // TV & elokuva
def get_is_tv_ja_elokuvat(max_days_old=365, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/tv-ja-elokuvat.xml', 'TV & elokuva', max_days_old, max_entries)
# is.fi // musiikki
def get_is_musiikki(max_days_old=365, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/musiikki.xml', 'musiikki', max_days_old, max_entries)
# is.fi // kuninkaalliset
def get_is_kuninkaalliset(max_days_old=1000, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/kuninkaalliset.xml', 'kuninkaalliset', max_days_old, max_entries)
# is.fi // horoskooppi
def get_is_horoskoopit(max_days_old=30, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/horoskooppi.xml', 'horoskoopit', max_days_old, max_entries)
# is.fi // urheilu
def get_is_urheilu(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/urheilu.xml', 'urheilu', max_days_old, max_entries)
# is.fi // jääkiekko
def get_is_jaakiekko(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/jaakiekko.xml', 'jääkiekko', max_days_old, max_entries)
# is.fi // tiede
def get_is_tiede(max_days_old=1000, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/tiede.xml', 'tiedeuutiset', max_days_old, max_entries)
# is.fi // jalkapallo
def get_is_jalkapallo(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/jalkapallo.xml', 'jalkapallo', max_days_old, max_entries)
# is.fi // ralli
def get_is_ralli(max_days_old=1000, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/ralli.xml', 'ralli', max_days_old, max_entries)
# is.fi // yleisurheilu
def get_is_yleisurheilu(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/yleisurheilu.xml', 'yleisurheilu', max_days_old, max_entries)
# is.fi // hiihto
def get_is_hiihto(max_days_old=1000, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/hiihtolajit.xml', 'hiihto', max_days_old, max_entries)
# is.fi // formula 1
def get_is_formula1(max_days_old=1000, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/formula1.xml', 'formula 1', max_days_old, max_entries)
# is.fi // ravit
def get_is_ravit(max_days_old=1000, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/ravit.xml', 'ravit', max_days_old, max_entries)
# is.fi // digitoday
def get_is_digitoday(max_days_old=1000, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/digitoday.xml', 'digitoday', max_days_old, max_entries)
# is.fi // esports
def get_is_esports(max_days_old=1000, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/digitoday/esports.xml', 'esports', max_days_old, max_entries)
# is.fi // autot
def get_is_autot(max_days_old=1000, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/autot.xml', 'autot', max_days_old, max_entries)
# is.fi // me naiset
def get_is_menaiset(max_days_old=365, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/menaiset.xml', 'me naiset', max_days_old, max_entries)
# is.fi // hyvä olo
def get_is_hyvaolo(max_days_old=365, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/hyvaolo.xml', 'hyvä olo', max_days_old, max_entries)
# is.fi // ruokala
def get_is_ruokala(max_days_old=365, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/ruokala.xml', 'ruokala', max_days_old, max_entries)
# is.fi // asuminen
def get_is_asuminen(max_days_old=365, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/asuminen.xml', 'asuminen', max_days_old, max_entries)
# is.fi // matkat
def get_is_matkat(max_days_old=365, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/matkat.xml', 'matkat', max_days_old, max_entries)
# is.fi // perhe
def get_is_perhe(max_days_old=365, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_is_rss_feed('https://www.is.fi/rss/perhe.xml', 'perhe', max_days_old, max_entries)
# #
# # )> YLE
# #
# overall rss fetcher for yle news
def fetch_and_process_yle_rss_feed(url, category_name, max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
try:
# Ensure max_days_old and max_entries are integers
max_days_old = int(max_days_old)
max_entries = int(max_entries)
# Fetch the RSS feed
response = requests.get(url)
# Parse the RSS feed
feed = feedparser.parse(response.content)
# Extract the headlines, descriptions, links, and pubDates
items = [{'title': entry.title, 'description': entry.description, 'link': entry.link, 'pubDate': entry.published}
for entry in feed.entries]
# Format the items with titles, descriptions, and elapsed time
formatted_items = []
current_time = datetime.now(pytz.UTC)
for item in items:
pub_date = datetime.strptime(item['pubDate'], "%a, %d %b %Y %H:%M:%S %z")
pub_date = pub_date.replace(tzinfo=pytz.UTC)
if (current_time - pub_date).days <= max_days_old:
time_elapsed = get_time_elapsed(pub_date)
formatted_item = f'<p><i>({time_elapsed})</i> <a href="{item["link"]}">{item["title"]}</a>: {item["description"]}</p>'
formatted_items.append(formatted_item)
if len(formatted_items) >= max_entries:
break
# Join the formatted items into a string with each item on a new line
items_string = '\n'.join(formatted_items)
items_string_out = f'Tässä yle.fi:n {category_name}:\n\n' + items_string
print_horizontal_line()
logging.info(items_string_out)
print_horizontal_line()
return {
'type': 'text',
'content': items_string_out,
'html': f'<ul>{items_string_out}</ul>'
}
except Exception as e:
logging.error(f"Error fetching yle.fi {category_name} news: {e}")
return {
'type': 'text',
'content': f"Sori! En päässyt käsiksi yle.fi:n {category_name}-uutisvirtaan. Mönkään meni! Pahoitteluni!",
'html': f"Sori! En päässyt käsiksi yle.fi:n {category_name}-uutisvirtaan. Mönkään meni! Pahoitteluni!"
}
def get_yle_latest_news(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed('https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET', 'tuoreimmat uutiset', max_days_old, max_entries)
def get_yle_main_news(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed('https://feeds.yle.fi/uutiset/v1/majorHeadlines/YLE_UUTISET.rss', 'pääuutiset', max_days_old, max_entries)
def get_yle_most_read(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed('https://feeds.yle.fi/uutiset/v1/mostRead/YLE_UUTISET.rss', 'luetuimmat uutiset', max_days_old, max_entries)
def get_yle_kotimaa(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed('https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-34837', 'kotimaan uutiset', max_days_old, max_entries)
def get_yle_kulttuuri(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed('https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-150067', 'kulttuuriuutiset', max_days_old, max_entries)
def get_yle_liikenne(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed('https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-12', 'liikenneuutiset', max_days_old, max_entries)
def get_yle_luonto(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed('https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-35354', 'luontouutiset', max_days_old, max_entries)
def get_yle_media(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed('https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-35057', 'mediauutiset', max_days_old, max_entries)
def get_yle_nakokulmat(max_days_old=365, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed('https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-35381', 'näkökulmat-uutiset', max_days_old, max_entries)
def get_yle_terveys(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed('https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-35138', 'terveysuutiset', max_days_old, max_entries)
def get_yle_tiede(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed('https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-819', 'tiedeuutiset', max_days_old, max_entries)
def get_yle_ulkomaat(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed('https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-34953', 'ulkomaan uutiset', max_days_old, max_entries)
def get_yle_urheilu(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed('https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_URHEILU', 'urheilu-uutiset', max_days_old, max_entries)
def get_yle_viihde(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed('https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-36066', 'viihdeuutiset', max_days_old, max_entries)
#
# > yle.fi regional news
#
def get_yle_etela_karjala(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed('https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-141372', 'Etelä-Karjalan uutiset', max_days_old, max_entries)
def get_yle_etela_pohjanmaa(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed(
'https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-146311',
'Etelä-Pohjanmaan uutiset', max_days_old, max_entries
)
def get_yle_etela_savo(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed(
'https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-141852',
'Etelä-Savon uutiset', max_days_old, max_entries
)
def get_yle_kainuu(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed(
'https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-141399',
'Kainuun uutiset',
max_days_old,
max_entries
)
def get_yle_kanta_hame(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed(
'https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-138727',
'Kanta-Hämeen uutiset',
max_days_old,
max_entries
)
def get_yle_keski_pohjanmaa(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed(
'https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-135629',
'Keski-Pohjanmaan uutiset',
max_days_old,
max_entries
)
def get_yle_keski_suomi(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed(
'https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-148148',
'Keski-Suomen uutiset',
max_days_old,
max_entries
)
def get_yle_kymenlaakso(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed(
'https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-131408',
'Kymenlaakson uutiset',
max_days_old,
max_entries
)
def get_yle_lappi(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed(
'https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-139752',
'Lapin uutiset',
max_days_old,
max_entries
)
def get_yle_pirkanmaa(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed(
'https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-146831',
'Pirkanmaan uutiset', max_days_old, max_entries
)
def get_yle_pohjanmaa(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed(
'https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-148149',
'Pohjanmaan uutiset', max_days_old, max_entries
)
def get_yle_pohjois_karjala(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed(
'https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-141936',
'Pohjois-Karjalan uutiset', max_days_old, max_entries
)
def get_yle_pohjois_pohjanmaa(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed(
'https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-148154',
'Pohjois-Pohjanmaan uutiset', max_days_old, max_entries
)
def get_yle_pohjois_savo(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed(
'https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-141764',
'Pohjois-Savon uutiset', max_days_old, max_entries
)
def get_yle_paijat_hame(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed(
'https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-141401',
'Päijät-Hämeen uutiset', max_days_old, max_entries
)
def get_yle_satakunta(max_days_old=DEFAULT_MAX_DAYS_OLD, max_entries=DEFAULT_MAX_ENTRIES):
return fetch_and_process_yle_rss_feed(
'https://feeds.yle.fi/uutiset/v1/recent.rss?publisherIds=YLE_UUTISET&concepts=18-139772',
'Satakunnan uutiset', max_days_old, max_entries