def generate_map_from_sources(job, data_sources, metadata_sources, debug=False):

    try:
        print("starting generate_map_from_sources w job")

        key = job['key']
        max_seconds = int(job.get('max_seconds', 10))
        countries = job.get('countries', [])
        admin1limits = job.get('admin1limits', [])
        order_id = job['order_id']
        extra_context = job.get("extra_context", {})
        end_user_timezone = extra_context.get("end_user_timezone", None)
        case_insensitive = extra_context.get("case_insensitive", None)

        # make directory to store input sources and final maps
        directory = join(MAPS_DIRECTORY, key)
        mkdir(directory)
        print("made directory:" + directory)

        max_source_text_length = next(f for f in Source._meta.fields if f.name == "source_text").max_length

        locations = []
        for source in data_sources:
            try:
                print("source:", source)
                source_type = source['type']
                source_data = source['data']
                if source_type == "text":
                    print("source_data:", source_data.encode("utf-8"))
                    print("[generator] creating source object")
                    source_text = source_data.encode("utf-8") if len(source_data.encode("utf-8")) < max_source_text_length else None
                    Source.objects.create(order_id=order_id, source_text=source_text, source_type="text")
                    print("[generator] created source object")
                    #save_text_to_file(source_data, toFileName(source_data, max_length=20))
                    locations.extend(extract_locations_from_text(source_data, case_insensitive=case_insensitive))
                elif (isinstance(source_data, str) or isinstance(source_data, str)) and validators.url(source_data):
                    print("source is url")

                    url = source_data.strip().strip('"').strip('"')

                    # we want to respect Google, so we avoid adding an automated click through
                    # by just directly getting the url
                    if url.startswith("https://www.google.com/url?"):
                        url = unquote(search("(?<=&url=)[^&]{10,}", url).group(0))

                    if not url.startswith("http"):
                        print("we assume that the user didn't include the protocol")
                        url = "http://" + url

                    Source.objects.create(order_id=order_id, source_url=url, source_type="url")

                    extension = url.split(".")[-1]
                    print("extension:", extension)