Skip to content

Commit

Permalink
First version with gopro and twitter module.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodolfosantos committed Jun 24, 2015
1 parent 1da683d commit eb966fc
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
68 changes: 68 additions & 0 deletions gopro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import requests
import re
import wget
import time

goproHTTPRoot = "http://10.5.5.9/videos/DCIM/"

def takeshot():
r = requests.get("http://10.5.5.9/gp/gpControl/command/shutter?p=1")
return r.status_code

def getFoldersList():
r = requests.get(goproHTTPRoot)
folderList = re.findall(r'href=".*/"', r.text)

folderListResult = []

for i in range(len(folderList)):
folderName = folderList[i].replace("href=\"", "").replace("\"", "")
folderListResult.append(folderName)

return folderListResult


def getPhotosNameList(folder):
r = requests.get(goproHTTPRoot + folder)
photoNameList = re.findall(r'href=".*.JPG"', r.text)

photoNameListResult = []

for i in range(len(photoNameList)):
photoName = photoNameList[i].replace("href=\"", "").replace("\"", "")
photoNameListResult.append(folder + photoName)

return photoNameListResult

def getAllPhotoPaths():
folders = getFoldersList()

result = []

for i in range(len(folders)):
photosNames = getPhotosNameList(folders[i])
for j in range(len(photosNames)):
result.append(photosNames[j])

return result

def getLastPhotoPath():
allPhotosPathsList = sorted(getAllPhotoPaths())
print allPhotosPathsList
return allPhotosPathsList[-1]

def downloadPhoto(url):
filename = wget.download(url)
return filename

def takePhotoAndDownload():
status = takeshot()
time.sleep(5)
lastPhoto = getLastPhotoPath()
return downloadPhoto(goproHTTPRoot + lastPhoto)



if __name__ == '__main__':
takenPhotoName = takePhotoAndDownload()
print takenPhotoName
8 changes: 8 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import gopro
import twitter


if __name__ == '__main__':
takenPhotoName = gopro.takePhotoAndDownload()
print twitter.tweet("Test", takenPhotoName)
print takenPhotoName
18 changes: 18 additions & 0 deletions twitter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import tweepy

# Consumer keys and access tokens, used for OAuth
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''

def tweet(status, photoPath):
# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

# Creation of the actual interface, using authentication
api = tweepy.API(auth)

# Send the tweet with photo
return api.update_with_media(photoPath, status=status)

0 comments on commit eb966fc

Please sign in to comment.