Created
November 13, 2016 21:28
-
-
Save tOverney/fb372ed0b2e446ae859a59c9ca1c6438 to your computer and use it in GitHub Desktop.
Simple script to upload the content of a folder `images`
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
#! /usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
import wget, os, flickrapi, webbrowser | |
from pathlib import PurePosixPath, PosixPath, Path | |
def path(elems): | |
return "/".join(elems) | |
OUT_DIR = "images" | |
BASE_DIR = os.getcwd() | |
API_KEY = "" # api key | |
API_SECRET = "" # api secret | |
pictures = [] | |
flickr = flickrapi.FlickrAPI(API_KEY, API_SECRET) | |
flickr.cache = None | |
if not os.path.exists(OUT_DIR): | |
os.makedirs(OUT_DIR) | |
def upload_to_flickr(): | |
print("Authenticating to flickr") | |
if not flickr.token_valid(perms = 'write'): | |
# Get a request token | |
flickr.get_request_token(oauth_callback = 'oob') | |
# Open a browser at the authentication URL. Do this however | |
# you want, as long as the user visits that URL. | |
authorize_url = flickr.auth_url(perms = 'write') | |
webbrowser.open_new_tab(authorize_url) | |
# Get the verifier code from the user. Do this however you | |
# want, as long as the user gives the application the code. | |
verifier = input('Verifier code: ') | |
# Trade the request token for an access token | |
flickr.get_access_token(verifier) | |
print("Uploading photos to flickr") | |
for pth in PosixPath(path([BASE_DIR, OUT_DIR])).iterdir(): | |
if ".DS_Store" not in pth.name: | |
print(" handling image: " + pth.name) | |
flickr.upload(str(pth)) | |
upload_to_flickr() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment