Пример #1
0
def get_quote(type):
    if type == 1:
        quotes, author = Quotes.get_random()
        print(quotes)
    if type == 2:
        name = input("enter authore name")
        count, quotes = Quotes.get_quote_by_author(name)
        for i in range(count):
            print(quotes[i])
    if type == 3:
        count, quotes, author = Quotes.get_all_quote()
        for i in range(count):
            print(quotes[i])
Пример #2
0
    def test_all_quote(self, mock_get):
        all_quote_response = {
            "count":
            2,
            "results": [{
                "_id": "5d91b45d9980192a317c87f3",
                "quoteText":
                "Doing nothing is better than being busy doing nothing.",
                "quoteAuthor": "Lao Tzu"
            }, {
                "_id": "5d91b45d9980192a317c87fa",
                "quoteText":
                "Work out your own salvation. Do not depend on others.",
                "quoteAuthor": "Buddha"
            }]
        }
        mock_get.return_value = Mock(ok=True)
        mock_get.return_value.json.return_value = all_quote_response

        expected = [
            "Doing nothing is better than being busy doing nothing.",
            "Work out your own salvation. Do not depend on others."
        ]

        all_quote_result_count, all_quote_result, all_quote_result_author = Quotes.get_all_quote(
        )
        self.assertEqual(all_quote_result, expected)
Пример #3
0
 def test_all_number_author(self, mock_get):
     all_quote_response = {
         "count":
         3,
         "results": [{
             "_id": "5d91b45d9980192a317c87f3",
             "quoteText":
             "Doing nothing is better than being busy doing nothing.",
             "quoteAuthor": "Lao Tzu"
         }, {
             "_id": "5d91b45d9980192a317c87fa",
             "quoteText":
             "Work out your own salvation. Do not depend on others.",
             "quoteAuthor": "Buddha"
         }, {
             "_id":
             "5d91b45d9980192a317c93ce",
             "quoteText":
             "What matters is the value we've created in our lives,"
             "the people we've made happy and how much we've grown as people.",
             "quoteAuthor":
             "Daisaku Ikeda"
         }]
     }
     mock_get.return_value = Mock(ok=True)
     mock_get.return_value.json.return_value = all_quote_response
     expected = 3
     all_quote_result_count, all_quote_result, all_quote_result_author = Quotes.get_all_quote(
     )
     self.assertEqual(len(all_quote_result_author), expected)
Пример #4
0
 def test_author_quote(self, mock_get):
     author_quote_response = {
         "count":
         2,
         "results": [{
             "_id": "5d91b45d9980192a317c87f3",
             "quoteText":
             "Doing nothing is better than being busy doing nothing.",
             "quoteAuthor": "Lao Tzu"
         }, {
             "_id": "5d91b45d9980192a317c87ed",
             "quoteText": "To lead people walk behind them.",
             "quoteAuthor": "Lao Tzu"
         }]
     }
     name = "Lao Tzu"
     mock_get.return_value = Mock(ok=True)
     mock_get.return_value.json.return_value = author_quote_response
     expected = [
         "Doing nothing is better than being busy doing nothing.",
         "To lead people walk behind them."
     ]
     author_quote_result_count, author_quote_result = Quotes.get_quote_by_author(
         name)
     self.assertEqual(author_quote_result, expected)
Пример #5
0
 def test_author_not_found_zero_quote(self, mock_get):
     all_quote_response = {"count": 0, "results": []}
     name = "Lao "
     mock_get.return_value = Mock(ok=True)
     mock_get.return_value.json.return_value = all_quote_response
     expected = []
     author_quote_result_count, author_quote_result = Quotes.get_quote_by_author(
         name)
     self.assertEqual(author_quote_result, expected)
Пример #6
0
death_case = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv'

if __name__ == "__main__":
    username = environ["USERNAME"]
    consumer_key = environ['KEY']
    consumer_secret = environ['SECRET']
    access_token = environ['TOKEN']
    access_token_secret = environ['TOKEN_SECRET']
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    api = tweepy.API(auth, wait_on_rate_limit=True)
    mad_bot = TwitterActions(api, username)

    while True:

        get_quote = Quotes()
        qotd = [
            get_quote.brainy(),
            get_quote.good_reads(),
            get_quote.good_housekeeping(),
            get_quote.keep_inspiring()
        ]
        random.shuffle(qotd)

        scrape = Websites()
        websites = [
            scrape.web(abc, 'doctype-article', abc[:-6], 'a', 'abcnews'),
            scrape.web(nine, 'feeds', nine, 'h3', 'ninenews'),
            scrape.web(bbc, 'media-list__item media-list__item--1', bbc, 'a',
                       'bbcnews'),
            scrape.web(ny_times, 'css-1qiat4j eqveam63', ny_times[:-1], 'h2',
Пример #7
0
if __name__ == "__main__":
    username = os.getenv("USERNAME")
    consumer_key = os.getenv("KEY")
    consumer_secret = os.getenv("SECRET")
    access_token = os.getenv("TOKEN")
    access_token_secret = os.getenv("TOKEN_SECRET")
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    api = tweepy.API(auth, wait_on_rate_limit=True)

    mad_bot = TwitterActions(api, username)

    while True:
        choice = display_menu(menu)
        if choice == 1:
            get_quote = Quotes()
            link = [get_quote.brainy(),
                    get_quote.good_reads()]
            random.shuffle(link)
            for i in range(len(link)):
                mad_bot.tweet_quote(link[i])
        elif choice == 2:
            mad_bot.tweet_random()
        elif choice == 3:
            url = input("Paste url: ")
            mad_bot.tweet_summary(url)
        elif choice == 4:
            scrape = Websites()
            link = [scrape.ny_times(),
                    scrape.nine_news(),
                    scrape.the_star(),