Post youtube soaring title to twitter with python3

tweet.py


#-- coding: utf-8 --
 
#Required library
import urllib.request as request
from bs4 import BeautifulSoup
from requests_oauthlib import OAuth1Session
 
#Set various twitter keys(Get the key yourself)
CK = ‘Consumer Key’
CS = ‘Consumer Secret’
AT = ‘Access Token’
AS = ‘Access Token Secret’
 
#URL for posting tweets
url = “https://api.twitter.com/1.1/statuses/update.json”
 
#OAuth authentication
twitter = OAuth1Session(CK, CS, AT, AS)
 
#Access the youtube soaring site
response = request.urlopen(‘https://www.youtube.com/feed/trending’)
body = response.read()
 
#Parse HTML
soup = BeautifulSoup(body, “lxml”)
 
#Scraping by specifying the class attribute of the soaring site
msg = soup.find_all(class_=’yt-uix-sessionlink yt-uix-tile-link yt-ui-ellipsis yt-ui-ellipsis-2 spf-link ‘)
 
status =“Youtube featured video\n”
 
#Substitute the three video titles from the top of the soaring site into the status variable
for i in range(0,3):
    status +=‘・’+ msg[i]['title'] + ‘\n’
 
#Tweet body
params = {“status”: status}
 
#Post to twitter
req = twitter.post(url, params = params)
 
#Output to console
print (status)

Recommended Posts

Post youtube soaring title to twitter with python3
Easily post to twitter with Python 3
Post to slack with Python 3
Post to Twitter using Python
[Lambda] [Python] Post to Twitter from Lambda!
Post multiple Twitter images with python
Steps to create a Twitter bot with python
Post an article with an image to WordPress with Python
Connect to BigQuery with Python
Post to vim → Python → Slack
Twitter graphing memo with Python
Get Twitter timeline with python
POST json with Python3 script
Use Twitter API with Python
Connect to Wikipedia with Python
Get Youtube data with python
YouTube video management with Python 3
Switch python to 2.7 with alternatives
Write to csv with Python
Search twitter tweets with python
Post to Slack in Python
Post a message to Google Hangouts Chat with a thread (Python)
Python: How to use async with
Link to get started with python
[Python] Write to csv file with Python
Create folders from '01' to '12' with python
Nice to meet you with python
Try to operate Facebook with Python
Post from python to facebook timeline
Output to csv file with Python
[Python] POST wav files with requests [POST]
Quine Post with Qiita API (Python)
Convert list to DataFrame with python
How to get started with Python
What to do with PYTHON release?
Post images from Python to Tumblr
Unable to install Python with pyenv
How to use FTP with Python
How to calculate date with python
[Nanonets] How to post Memo [Python]
I want to debug with Python
[Memo] Tweet on twitter with python
I tried to make a 2channel post notification application with Python
Collecting information from Twitter with Python (Twitter API)
Try to reproduce color film with Python
How to title multiple figures with matplotlib
Try logging in to qiita with Python
Change Python 64bit environment to 32bit environment with Anaconda
English speech recognition with python [speech to text]
Convert memo at once with Python 2to3
HTML email with image to send with python
I want to tweet on Twitter with Python, but I'm addicted to it
Memo to ask for KPI with python
Python to remember only with hello, worlds
Output color characters to pretty with python
Introduction to Python Image Inflating Image inflating with ImageDataGenerator
POST variously with Python and receive with Flask
Output Python log to console with GAE
Tweet from python with Twitter Developer + Tweepy
Convert Excel data to JSON with python
Convert Hiragana to Romaji with Python (Beta)