<commit_before>#!/usr/bin/env python
import feedparser # pip install feedparser
import asyncio


async def get(url):
    print("Start: %s" % url)
    response = await feedparser.parse(url)
    print("Finish: %s" % url)
    response.close()
    return 1


async def run_all(url1, url2):
    r1 = get(url1)
    r2 = get(url2)
    results = await asyncio.gather(r1, r2)

    for res in results:
        print(res)


loop = asyncio.get_event_loop()
loop.run_until_complete(run_all("http://rss.cnn.com/rss/edition.rss", "http://rss.cnn.com/rss/edition_world.rss"))
loop.close()

# from pymongo import MongoClient

# def Type1parser(url,source,category,type):
#     d = feedparser.parse(url)

#     for item in d['items']:
#         if  'description' in item:
#             print(item['description'])


#         print("\n")




# def main():
#     Type1parser("http://rss.cnn.com/rss/edition.rss","CNN","General","Latest")






# if __name__  ==  '__main__':
#     main()<commit_msg>This is a mess.Completed crude adaptation of api calls,No idea how to clean this<commit_after>#!/usr/bin/env python
import feedparser # pip install feedparser
from pymongo import MongoClient
import json
import re
import datetime

def Type1parser(url,source,category,tag):
    """

    This class handles all the feed parsing jobs initialted by the main function

    """


    feed = feedparser.parse(url)
    posts = []
    for item in feed['entries']:


        summarys=""
        if 'summary' in item:
            summarys=item.summary
        publishedTag=""
        if 'published' in item:
            publishedTag=item.published
        if 'media_content' in item:
             posts.append({
            'title': item.title,
            'summary': summarys,
            'link': item.link,
            'image':item.media_content[0]['url'],
            'published':publishedTag,
            'source':source,
            'category':category,
            'type':tag
        })

        print(item.title)
    # print(json.dumps(posts))







def main():
    """  Calling the main class parser for appropriate  rss feeds """


    Type1parser("http://rss.cnn.com/rss/edition.rss","CNN","General","Top")
    Type1parser("http://rss.cnn.com/rss/edition_world.rss","CNN","World","Top")
    Type1parser("http://rss.cnn.com/rss/edition_technology.rss","CNN","Technology","Top")
    Type1parser("http://rss.cnn.com/rss/edition_space.rss","CNN","Science","Top")
    Type1parser("http://rss.cnn.com/rss/edition_entertainment.rss","CNN","Entertainment","Top")
    Type1parser("http://rss.cnn.com/rss/cnn_latest.rss","CNN","General","Latest")
    print("\n")


    Type1parser("http://feeds.bbci.co.uk/news/rss.xml","BBC","General","Top")
    Type1parser("http://feeds.bbci.co.uk/news/world/rss.xml","BBC","World","Top")
    Type1parser("http://feeds.bbci.co.uk/news/politics/rss.xml","BBC","Politics","Top")
    Type1parser("http://feeds.bbci.co.uk/news/business/rss.xml","BBC","Business","Top")
    Type1parser("http://feeds.bbci.co.uk/news/health/rss.xml","BBC","Health","Top")
    Type1parser("http://feeds.bbci.co.uk/news/education/rss.xml","BBC","Education","Top")
    Type1parser("http://feeds.bbci.co.uk/news/science_and_environment/rss.xml","BBC","Science","Top")
    Type1parser("http://feeds.bbci.co.uk/news/technology/rss.xml","BBC","Technology","Top")
    Type1parser("http://feeds.bbci.co.uk/news/entertainment_and_arts/rss.xml","BBC","Entertainment","Top")







if __name__  ==  '__main__':
    main()
{'fraction_non_alphanumeric': 0.17650429799426934, 'fraction_numerical': 0.008022922636103151, 'mean_word_length': 3.283435582822086, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 9}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2023437', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1153, 'n_words': 183}