-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathimgur.py
More file actions
executable file
·107 lines (81 loc) · 2.62 KB
/
imgur.py
File metadata and controls
executable file
·107 lines (81 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python2
import Tkinter as tk
from PIL import Image, ImageTk
import json
from pprint import pprint
import os
import pyimgur
CLIENT_ID = "3646d99ff2928d0"
UPLOADED_FILES_JSON = "/home/fakedrake/bin/imgur.json"
HELP = ""
class MyImg(object):
link = "a link"
def upload_image(self, *ar, **kw):
return MyImg()
def upload_image(path, title, jsondb=UPLOADED_FILES_JSON):
if os.path.isfile(jsondb):
imgs = json.load(open(jsondb))
else:
imgs = dict() # path->link
if path in imgs:
link = imgs[path]
else:
im = pyimgur.Imgur(CLIENT_ID)
img = im.upload_image(path, title=title)
imgs[path] = img.link
open(jsondb, "w+").write(json.dumps(imgs))
link = img.link
return link
def isimage(fname):
for ext in [".png", ".jpg", ".gif"]:
if fname.endswith(ext):
return True
return False
def images_in(rootdir="/home/fakedrake/Pictures/"):
flist = []
for root, subfolders, files in os.walk(rootdir):
flist += [os.path.join(root, f) for f in files
if isimage(f)]
return sorted(flist, reverse=True, key=lambda f: os.path.getctime(f))
def show_image(path):
root = tk.Tk()
root.title('background image')
# pick an image file you have .bmp .jpg .gif. .png
# load the file and covert it to a Tkinter image object
imageFile = path
image1 = ImageTk.PhotoImage(Image.open(imageFile))
# get the image size
w = image1.width()
h = image1.height()
# position coordinates of root 'upper left corner'
x = 0
y = 0
# make the root window the size of the image
root.geometry("%dx%d+%d+%d" % (w, h, x, y))
# root has no image argument, so use a label as a panel
panel1 = tk.Label(root, image=image1)
panel1.pack(side='top', fill='both', expand='yes')
# save the panel's image from 'garbage collection'
panel1.image = image1
# start the event loop
root.mainloop()
if __name__ == "__main__":
print "Usage: imgur [<title> [image number]]"
import sys
a = sys.argv
imgsf = images_in()
title = a[1] if len(a) > 1 else "<Untitled>"
upc = int(a[2]) if len(a) > 2 else 0
print "Uploading image (kill script to cancel)"
print "\tTile:", title
print "\tFname (%dth newest):", imgsf[upc]
print ""
print "Recet images:"
for i, im in enumerate(imgsf[:10]):
print "\t%d: %s" % (i, im)
print "To upload close window, to cancel kill script..."
show_image(imgsf[upc])
print "Uploading...",
url = upload_image(imgsf[upc], title)
print "Done"
print "URL:", url