forked from b3nab/instapy-cli
-
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.
new feature: upload a photo from link, release 0.0.4
- Loading branch information
Showing
6 changed files
with
69 additions
and
10 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
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
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
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
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,39 @@ | ||
import os, requests | ||
#import urlparse for Python2 and Python3 | ||
try: | ||
from urllib.parse import urlparse | ||
except ImportError: | ||
from urlparse import urlparse | ||
|
||
|
||
class Media(object): | ||
pathFile = None | ||
media = None | ||
isLink = False | ||
|
||
def __init__(self, file): | ||
self.media = file | ||
# if file is link | ||
if urlparse(file).scheme in ('http', 'https'): | ||
self.pathFile = self.downloadMediaFromLink(file) | ||
self.isLink = True | ||
# if file is a local file | ||
else: | ||
self.pathFile = file | ||
|
||
def getPath(self): | ||
return self.pathFile | ||
|
||
def isLink(self): | ||
return self.isLink | ||
|
||
def downloadMediaFromLink(self,url): | ||
# print(urlparse(url)) | ||
fileName = urlparse(url).path.split('/')[-1] | ||
print(fileName) | ||
r = requests.get(url, allow_redirects=True) | ||
open(fileName, 'wb').write(r.content) | ||
return fileName | ||
|
||
def removeMedia(self): | ||
os.remove(self.pathFile) |
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