I'm trying to get this code to pull the media from any tweet that mentions my twitter handle, convert it using ffmpeg via the subprocess module, then send the converted media back to the person as a reply.
import tweepy
from tweepy import Stream
from tweepy.streaming import StreamListener
from datetime import datetime
import time
import subprocess
stdout = subprocess.PIPE
def runcmd(cmd):
x = subprocess.Popen(cmd, stdout=subprocess.PIPE)
return x.communicate(stdout)
import json
import random
class StdOutListener(StreamListener):
def on_data(self, data):
clean_data = json.loads(data)
tweetId = clean_data['id']
tweet_name = clean_data['user']['screen_name']
tweet_media = clean_data['entities']['media'][0]['media_url']
print(tweet_media)
tweet_photo = runcmd('ffmpeg -i', tweet_media, 'output.jpg')
tweet = 'Here ya go'
now = datetime.now()
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
print(' Reply sent to @'+tweet_name, 'on', dt_string, '\n' ' Message:', tweet, '\n')
respondToTweet(tweet_media, tweet, tweetId)
But I always end up getting this error:
Exception has occurred: TypeError
runcmd() takes 1 positional argument but 3 were given
tweet_photo = runcmd('ffmpeg -i', tweet_media, 'output.jpg')
So obviously, I can't put tweet_media
in between ffmpeg -i
and output.jpg
so how would I go about converting tweet_media
without errors?