S-11 commited on
Commit
5c07ffc
1 Parent(s): 99b936d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -61,6 +61,7 @@ def load_file_id_mapping():
61
  file_id_mapping = load_file_id_mapping()
62
 
63
  selected_websites = {}
 
64
 
65
  for website, details in config.items():
66
  if st.checkbox(website, key=website):
@@ -70,8 +71,11 @@ for website, details in config.items():
70
  language = st.selectbox(f'Choose language for {website}', list(languages.keys()), key=f'lang_{website}')
71
  selected_websites[website] = f"{website}_{language}" # like: hespress_en
72
  else:
 
73
  selected_websites[website] = website # like: akhbarona
74
 
 
 
75
  # Category selection
76
  categories = languages.get(language, {})
77
  if categories:
@@ -90,7 +94,11 @@ if st.button('Start Scraping'):
90
  for website, module_name in selected_websites.items():
91
  scraper_module = importlib.import_module(module_name)
92
  for category in selected_categories.get(website, []):
93
- category_url = config[website]['languages'][language][category]
 
 
 
 
94
  if 'category_name' in config[website]:
95
  category_name = config[website]['category_name'].get(category, 'default_category_name')
96
  file_path = scraper_module.scrape_category(category_url, num_articles)
 
61
  file_id_mapping = load_file_id_mapping()
62
 
63
  selected_websites = {}
64
+ selected_languages = {}
65
 
66
  for website, details in config.items():
67
  if st.checkbox(website, key=website):
 
71
  language = st.selectbox(f'Choose language for {website}', list(languages.keys()), key=f'lang_{website}')
72
  selected_websites[website] = f"{website}_{language}" # like: hespress_en
73
  else:
74
+ language = next(iter(languages.keys()))
75
  selected_websites[website] = website # like: akhbarona
76
 
77
+ selected_languages[website] = language
78
+
79
  # Category selection
80
  categories = languages.get(language, {})
81
  if categories:
 
94
  for website, module_name in selected_websites.items():
95
  scraper_module = importlib.import_module(module_name)
96
  for category in selected_categories.get(website, []):
97
+ try:
98
+ language = selected_languages[website]
99
+ category_url = config[website]['languages'][language][category]
100
+ except KeyError:
101
+ st.error(f"KeyError: {category} not found for {language} language in {website}.")
102
  if 'category_name' in config[website]:
103
  category_name = config[website]['category_name'].get(category, 'default_category_name')
104
  file_path = scraper_module.scrape_category(category_url, num_articles)