Example #1
0
def main(json_pref_loc, opt, credentials_loc, printonly=None):
    contentparser = ContentParser()
    contentchooser = ContentChooser()

    bpref = json_actions.read_json_file(json_pref_loc)
    credentials = json_actions.read_json_file(credentials_loc)
    # 1. parse options and fill in data structure
    item = contentparser.get_content_requirements(bpref[opt])
    # 2. get the items specified by options
    item = contentchooser.create_item(item)
    # 3. broadcast the item
    if printonly:
        print("Image: " + item.item_image_path + " Text: " + item.item_text)
    else:
        broadcast(item, credentials)
    def test_pop_first_record_json(self):
        expected = [[]]
        element = json_actions.pop_element_write_json(self.queue_file_loc, 0)
        self.assertEqual('direct', element[0]['selection_alg'])

        result = json_actions.read_json_file(self.queue_file_loc)
        self.assertEqual(expected, result)
    def get_artist_info(directory1, artist_name):
        directory = directory1 + r"\artists.json"
        artist_data = json_actions.read_json_file(directory)

        print("name: " + artist_name + " directory: " + directory)
        name = ""
        website = ""
        artstation = ""
        deviantart = ""

        # TODO: when found - quit loop
        # find info about artist in the json file
        for i in artist_data:

            name1 = i["Name"]
            # print(name1)
            if name1 == artist_name:
                name = i["Name"]
                if i["website"]:
                    website = i["website"]
                if i["artstation"]:
                    artstation = i["artstation"]
                if i["deviantart"]:
                    deviantart = i["deviantart"]
                return name, website, artstation, deviantart
            # else:
            #    return name, website, artstation, deviantart
            # TODO: return just empty is file has no artist name

        # name1 = artist_data[0]["Name"]
        # while name1 != artist_name:

        return name, website, artstation, deviantart
    def get_files_from_list(self, directory):
        # parse list / get first item from list
        broadcast_queue = json_actions.read_json_file(directory)

        # detele the first item from the list

        # return directories to files
        return broadcast_queue[0]
    def setUp(self):
        self.mockinfo = Mockinfo()
        #self.fileman = FileManager()

        # populate queue file for test_pop_first_record_json
        self.queue_original_file_loc = self.mockinfo.mockdir + "/posting_queue_original.json"
        self.queue_file_loc = self.mockinfo.mockdir + "/posting_queue.json"
        queue_data_original = json_actions.read_json_file(
            self.queue_original_file_loc)
        json_actions.write_json(self.queue_file_loc, queue_data_original)
    def get_anime_info(directory):
        # directory = directory + "\infogeneral.json"
        directory = directory + "/infogeneral.json"
        anime_data = json_actions.read_json_file(directory)

        english_name = anime_data["English Name"]
        japanese_name = anime_data["Japanese Name"]
        year = anime_data["Year"]

        return english_name, japanese_name, year
 def get_history(self, history_file, file_type):
     if file_type == "json":
         return json_actions.read_json_file(history_file)
     elif file_type == "database":
         return None
    def get_values_json(self, directory, filename):
        directory = dir_actions.unite_dir_with_fname(directory, filename)

        data = json_actions.read_json_file(directory)

        return tuple(self.get_values_from_kv_pairs(data))