Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timothyclemansinsea/c75618f11f1cc5c9400302029370a6a0 to your computer and use it in GitHub Desktop.
Save timothyclemansinsea/c75618f11f1cc5c9400302029370a6a0 to your computer and use it in GitHub Desktop.
import tweepy
import os
import json
def get_api(cfg):
auth = tweepy.OAuthHandler(cfg['consumer_key'], cfg['consumer_secret'])
auth.set_access_token(cfg['access_token'], cfg['access_token_secret'])
return tweepy.API(auth)
def main():
# Fill in the values noted in previous step here
cfg = {
"consumer_key" : "",
"consumer_secret" : "",
"access_token" : "",
"access_token_secret" : ""
}
skip = os.listdir('/mnt/c/Users/polic/recordings/')
while True:
new = set(os.listdir('/mnt/c/Users/polic/recordings/')) - set(skip)
for f in sorted(new):
if '3312' in f and f.endswith('.wav'):
skip.append(f)
while True:
try:
with open('/mnt/c/Users/polic/recordings/'+f, 'r') as fi:
fi.read()
os.system('flac --best -f /mnt/c/Users/polic/recordings/%s' % (f))
result = ''
jresult = json.loads(os.popen('python speech_rest.py /mnt/c/Users/polic/recordings/%s' % (f.replace('wav', 'flac'))).read())
print jresult
try:
result = jresult["results"][0]["alternatives"][0]["transcript"]
except:
pass
break
except:
print 'looping'
os.system('./dropbox_uploader.sh upload /mnt/c/Users/polic/recordings/%s /public/radio_transmissions/%s' % (f, f))
url = os.popen('./dropbox_uploader.sh share /public/radio_transmissions/%s' % (f)).read()
print 'url', url
url = url[url.find('http'):].strip()
api = get_api(cfg)
tweet = url + ' ' + result
tweet = tweet[:140]
print 'tweet', tweet
status = api.update_status(status=tweet)
#return
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment