def run(filter_field, value): reader = CSV_Manager("./articles.csv") articles = reader.get_csv_as_dicts() manipulator = Manipulator(articles) filtered = manipulator.filter_by(filter_field, value) print(json.dumps(filtered, indent=2))
def filter_CSV(filter_field, value): reader = CSV_Manager("./articles.csv") articles = reader.get_csv_as_dicts() manipulator = Manipulator(articles) filtered = manipulator.filter_by(filter_field, value) return list(filtered)
def is_article(key, value): reader = CSV_Manager("./articles.csv") articles = reader.get_csv_as_dicts() for i in articles: if i[key] == value: return True return False
def count_articles(key, value): count = 0 reader = CSV_Manager("./articles.csv") articles = reader.get_csv_as_dicts() for i in articles: if i[key] == value: count = count + 1 return count
def longest_article(key, value): reader = CSV_Manager("./articles.csv") articles = reader.get_csv_as_dicts() longest = articles[1] for i in articles: if i[key] == value: if i['pages'] > longest['pages']: longest = i return longest
def longest_article(filter_field, value): reader = CSV_Manager("./articles.csv") articles = reader.get_csv_as_dicts() del articles[0] filtered_articles = filter_CSV(filter_field, value) lng_article = filtered_articles[0] for article in filtered_articles: if article["pages"] > lng_article["pages"]: lng_article = article return lng_article
def run(filter_field, value=None): reader = CSV_Manager("./articles.csv") if value != None: articles = reader.get_csv_as_dicts() manipulator = Manipulator(articles) filtered = manipulator.filter_by(filter_field, value) print(json.dumps(filtered, indent=2)) else: a = reader.map_author() print(json.dumps(a[filter_field], indent=2))
def run(filter_field, value=False): reader = CSV_Manager("./articles.csv") if value: articles = reader.get_csv_as_dicts() manipulator = Manipulator(articles) filtered = manipulator.filter_by(filter_field, value) print(json.dumps(filtered, indent=2)) else: reader.read() manipulator = Manipulator(reader.mapped_dict) manipulator.relevant(filter_field)
def edit_data(): reader = CSV_Manager("./articles.csv") articles = reader.get_csv_as_dicts() new_data = {} for i in articles: if i['author'] not in new_data: new_data[i['author']] = [] new_data[i['author']].append( {i['title'], i['date'], i['category'], i['pages']}) if i['category'] not in new_data: new_data[i['category']] = [] new_data[i['category']].append( {i['title'], i['date'], i['author'], i['pages']}) print(new_data)
def filter_CSV(filter_field, value): reader = CSV_Manager("./articles.csv") articles = reader.get_csv_as_dicts() manipulator = Manipulator(articles) filtered = manipulator.filter_by(filter_field, value) return list(filtered) def count_articles(filter_field, value): filtered = filter_CSV(filter_field, value) return len(filtered) def is_article(filter_field, value): return count_articles(filter_field, value) > 0 def longest_article(filter_field, value): filtered = filter_CSV(filter_field, value) max = 0 for a in filtered: if (int(a['pages']) > max): max = int(a['pages']) article = a return article reader = CSV_Manager("./articles.csv") articles = reader.get_csv_as_dicts() print(reader.to_obj(articles))