예제 #1
0
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))
예제 #2
0
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)
예제 #3
0
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
예제 #4
0
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
예제 #5
0
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
예제 #6
0
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        
예제 #7
0
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))
예제 #8
0
파일: main.py 프로젝트: LhChrchm/rand-sim-3
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)
예제 #9
0
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)
예제 #10
0
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))