-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First version with gopro and twitter module.
- Loading branch information
1 parent
1da683d
commit eb966fc
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |