Exemple #1
0
def news_command(bot, update):
    print("ok")
    try:
        user_text = update.message.text
        input_num = user_text.split(" ")
        limit_news = int(
            input_num[1]
        )  # Lấy tham số từ input truyền vào -> cào về bao nhiêu tin
        print(limit_news)
        news = News.GetNews(limit_news)
        print('news', news)
        for x in range(
                0, len(news)
        ):  # Deserialize dữ liệu json trả về từ file News.py lúc nãy
            message = json.loads(news[x])
            print(message)
            update.message.reply_text(message['title'] + "\n" +
                                      message['link'] + "\n" +
                                      message['description'])
    except (IndexError, ValueError):
        update.message.reply_text('Vui lòng chọn số lượng tin hiển thị!!')
Exemple #2
0
                        "Understood ! Opening Youtube with result of" + name)
                    Youtube.YTSearch(name)

        # ---------------------------------------------------------------------------------------------------------#
        elif type == "2":
            Firefox.joinYT()

# -----------------------------------------------------------------------------------------------#--
#She will trigger the Facebook.py
    if string == "facebook" or string == "FaceBook":
        Speak_Function(
            "Understood Sir! Do you want me to log in Facebook for you ")
        choose = input("Your choice: \n" "1: Yes \n" "2: No \n" "Your Order: ")
        # ---------------------------------------------------------------------------------------------------------#
        if choose == "1":
            Facebook.Facebook()

        # ---------------------------------------------------------------------------------------------------------#
        elif choose == "2":
            Speak_Function("Understood! Opening Face Book")
            Firefox.joinFB()

# -----------------------------------------------------------------------------------------------#--

#She will trigger the News.py
    elif string == "update me":
        Speak_Function("Understood Sir! Here are all the new today ")
        News.GetNews()

# -----------------------------------------------------------------------------------------------#--
Exemple #3
0
        access_token = Config["access_token"]
        access_token_secret = Config["access_token_secret"]
        delay = Config["CheckNewsEveryXSeconds"]
except:
    sys.exit()
    print("Sorry something went wrong while reading the config file.")

try:
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    redirect_url = auth.get_authorization_url()
    api = tweepy.API(auth)
except tweepy.TweepError:
    sys.exit()
    print("Sorry the Auth you are using is invaild.")

while True:
    FortniteGame = requests.get("https://fortnitecontent-website-prod07.ol.epicgames.com/content/api/pages/fortnite-game",headers={'Accept-Language' : Language.lower()}).json()["battleroyalenews"]["news"]["messages"]
    
    with open("StoredNews.json") as f:
        StoredNews = json.loads(f.read()) #Load the stored news

    if FortniteGame != StoredNews: #If the news on the api aren't the same as stored on the file
        News.GetNews().save("News.png") #Idk how to post the image directly on twitter... so we need to save it as a file first
        api.update_with_media("News.png")#Upload the image

        with open("StoredNews.json","w+") as f:
            f.write(json.dumps(FortniteGame)) #Overwrites the old news
        print("Uploaded News on Twitter")
    else:
        time.sleep(delay) #The script will wait for 5 Seconds