#!/usr/bin/python
# -*- coding: utf-8 -*-

from Channels.News_Channel import newsdownload, newsmake
from .newsdownload import News
from .newsmake import process_news
import sys
import threading
from utils import *


def main():
    print("News Channel File Generator \nBy Larsen Vallecillo / www.rc24.xyz\n")
    if len(sys.argv) > 1:
        download(sys.argv[1])
    else:
        threads = []

        sources = [
            "ap_english",
            "ap_spanish",
            "reuters_europe_english",
            "afp_french",
            "afp_german",
            "afp_spanish",
            "ansa_italian",
            "anp_dutch",
            "reuters_japanese",
        ]

        for source in sources:
            t = threading.Thread(target=download, args=(source,))
            threads.append(t)
            t.start()

        for t in threads:
            t.join()


def download(source):
    try:
        if source == "ap_english":
            process_news("AP English", "ap_english", 1, "America", News("ap_english"))
        elif source == "ap_spanish":
            process_news("AP Spanish", "ap_spanish", 4, "America", News("ap_spanish"))
        elif source == "reuters_europe_english":
            process_news(
                "Reuters Europe English",
                "reuters_europe_english",
                1,
                "Europe",
                News("reuters_europe_english"),
            )
        elif source == "afp_french":
            process_news(
                "AFP French", "afp_french", 3, "International", News("afp_french")
            )
        elif source == "afp_german":
            process_news("AFP German", "afp_german", 2, "Europe", News("afp_german"))
        elif source == "afp_spanish":
            process_news("AFP Spanish", "afp_spanish", 4, "Europe", News("afp_spanish"))
        elif source == "ansa_italian":
            process_news(
                "ANSA Italian", "ansa_italian", 5, "Europe", News("ansa_italian")
            )
        elif source == "anp_dutch":
            process_news("ANP Dutch", "anp_dutch", 6, "Europe", News("anp_dutch"))
        elif source == "reuters_japanese":
            process_news(
                "Reuters Japanese",
                "reuters_japanese",
                0,
                "Japan",
                News("reuters_japanese"),
            )
        else:
            print("Invalid source specified.")
            exit()
    except Exception as e:
        print("Failed to make news for " + source + ".")
        raise e


if __name__ == "__main__":
    main()

@@ -174,25 +174,8 @@
 sys%0A
-import threading%0A
 from
@@ -363,54 +363,17 @@
     
-threads = %5B%5D%0A%0A        sources = %5B%0A            
+download(
 %22ap_
@@ -372,33 +372,33 @@
 oad(%22ap_english%22
-,
+)
 %0A            %22ap
@@ -390,20 +390,25 @@
         
-    
+download(
 %22ap_span
@@ -403,33 +403,33 @@
 oad(%22ap_spanish%22
-,
+)
 %0A            %22re
@@ -413,36 +413,41 @@
 anish%22)%0A        
-    
+download(
 %22reuters_europe_
@@ -446,33 +446,33 @@
 _europe_english%22
-,
+)
 %0A            %22af
@@ -460,28 +460,33 @@
 h%22)%0A        
-    
+download(
 %22afp_french%22
@@ -485,28 +485,26 @@
 _french%22
-,%0A  
+)%0A
         
   %22afp_g
@@ -491,26 +491,33 @@
 h%22)%0A        
-  
+download(
 %22afp_german%22
@@ -516,17 +516,17 @@
 _german%22
-,
+)
 %0A       
@@ -526,20 +526,25 @@
         
-    
+download(
 %22afp_spa
@@ -544,25 +544,25 @@
 afp_spanish%22
-,
+)
 %0A           
@@ -558,20 +558,25 @@
         
-    
+download(
 %22ansa_it
@@ -581,17 +581,17 @@
 italian%22
-,
+)
 %0A       
@@ -591,20 +591,25 @@
         
-    
+download(
 %22anp_dut
@@ -611,17 +611,17 @@
 p_dutch%22
-,
+)
 %0A       
@@ -625,238 +625,35 @@
     
-    %22reuters_japanese%22,%0A        %5D%0A%0A        for source in sources:%0A            t = threading.Thread(target=download, args=(source,))%0A            threads.append(t)%0A            t.start()%0A%0A        for t in threads:%0A            t.join(
+download(%22reuters_japanese%22
 )%0A%0A%0A

Revert threading