Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

#!/usr/local/bin/python 

# encoding: utf-8 

""" 

Documentation for picaxe can be found here: http://picaxe.readthedocs.org/en/stable 

 

Usage: 

picaxe init 

picaxe auth [-s <pathToSettingsFile>] 

picaxe md <urlOrPhotoid> [<width>] [-s <pathToSettingsFile>] 

picaxe albums [-s <pathToSettingsFile>] 

picaxe [-giop] upload <imagePath> [--title=<title> --tags=<tags> --desc=<desc> --album=<album>] 

picaxe [-op] grab [--title=<title> --tags=<tags> --desc=<desc> --album=<album> --delay=<sec>] 

 

Options: 

init setup the polygot settings file for the first time 

auth authenticate picaxe against your flickr account 

md generate the MD reference link for the image in the given flickr URL 

albums list all the albums in the flickr account 

upload upload a local image to flickr 

 

<pathToSettingsFile> path to the picaxe settings file 

<urlOrPhotoid> the flickr URL or photoid 

<width> pixel width resolution of the linked image. Default *original*. [75|100|150|240|320|500|640|800|1024|1600|2048] 

<imagePath> path to the local image to upload to flickr 

 

--title=<title> the image title 

--tags=<tags> quoted, comma-sepatated tags 

--desc=<desc> image description 

--delay=<sec> the delay time before screen-grab selection tool appears 

 

-p, --public make the image public (private by default) 

-o, --open open the image in the flickr web-app once uploaded 

-i, --image "photo" is an image 

-g, --screenGrab "photo" is a screengrab 

-h, --help show this help message 

-v, --version show version 

-s, --settings the settings file 

""" 

################# GLOBAL IMPORTS #################### 

import sys 

import os 

os.environ['TERM'] = 'vt100' 

import readline 

import glob 

import pickle 

import time 

from docopt import docopt 

from fundamentals import tools, times 

# from ..__init__ import * 

 

 

def main(arguments=None): 

""" 

*The main function used when ``cl_utils.py`` is run as a single script from the cl, or when installed as a cl command* 

""" 

# setup the command-line util settings 

su = tools( 

arguments=arguments, 

docString=__doc__, 

logLevel="DEBUG", 

options_first=False, 

projectName="picaxe" 

) 

arguments, settings, log, dbConn = su.setup() 

 

startTime = times.get_now_sql_datetime() 

 

# unpack remaining cl arguments using `exec` to setup the variable names 

# automatically 

for arg, val in arguments.iteritems(): 

if arg[0] == "-": 

varname = arg.replace("-", "") + "Flag" 

else: 

varname = arg.replace("<", "").replace(">", "") 

if isinstance(val, str) or isinstance(val, unicode): 

exec(varname + " = '%s'" % (val,)) 

else: 

exec(varname + " = %s" % (val,)) 

if arg == "--dbConn": 

dbConn = val 

log.debug('%s = %s' % (varname, val,)) 

 

if init: 

from os.path import expanduser 

home = expanduser("~") 

filepath = home + "/.config/picaxe/picaxe.yaml" 

try: 

cmd = """open %(filepath)s""" % locals() 

p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True) 

except: 

pass 

try: 

cmd = """start %(filepath)s""" % locals() 

p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True) 

except: 

pass 

 

if auth: 

from picaxe import picaxe 

client = picaxe( 

log=log, 

settings=settings, 

pathToSettingsFile=pathToSettingsFile 

) 

client.authenticate() 

 

if md: 

from picaxe import picaxe 

Flickr = picaxe( 

log=log, 

settings=settings 

) 

if not width: 

width = "original" 

mdLink = Flickr.md( 

url=urlOrPhotoid, 

# [75, 100, 150, 240, 320, 500, 640, 800, 1024, 1600, 2048] 

width=width 

) 

print mdLink 

 

if albums: 

from picaxe import picaxe 

flickr = picaxe( 

log=log, 

settings=settings 

) 

albumList = flickr.list_album_titles() 

for a in albumList: 

print a 

 

if upload: 

from picaxe import picaxe 

flickr = picaxe( 

log=log, 

settings=settings 

) 

 

imageType = "photo" 

if screenGrabFlag: 

imageType = "screengrab" 

elif imageFlag: 

imageType = "image" 

 

album = "inbox" 

if albumFlag: 

album = albumFlag 

 

photoid = flickr.upload( 

imagePath=imagePath, 

title=titleFlag, 

private=publicFlag, 

tags=tagsFlag, 

description=descFlag, 

imageType=imageType, # image|screengrab|photo 

album=albumFlag, 

openInBrowser=openFlag 

) 

print photoid 

 

if grab: 

 

# for k, v in locals().iteritems(): 

# print k, v 

# return 

try: 

os.remove("/tmp/screengrab.png") 

except: 

pass 

 

if delayFlag: 

 

time.sleep(int(delayFlag)) 

 

from subprocess import Popen, PIPE, STDOUT 

cmd = """screencapture -i /tmp/screengrab.png""" % locals() 

p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True) 

stdout, stderr = p.communicate() 

log.debug('output: %(stdout)s' % locals()) 

 

exists = os.path.exists("/tmp/screengrab.png") 

if exists: 

from picaxe import picaxe 

flickr = picaxe( 

log=log, 

settings=settings 

) 

 

if not albumFlag: 

albumFlag = "screengrabs" 

 

photoid = flickr.upload( 

imagePath="/tmp/screengrab.png", 

title=titleFlag, 

private=publicFlag, 

tags=tagsFlag, 

description=descFlag, 

imageType="screengrab", # image|screengrab|photo 

album=albumFlag, 

openInBrowser=openFlag 

) 

mdLink = flickr.md( 

url=photoid, 

# [75, 100, 150, 240, 320, 500, 640, 800, 1024, 1600, 2048] 

width="original" 

) 

print mdLink 

 

# CALL FUNCTIONS/OBJECTS 

 

if "dbConn" in locals() and dbConn: 

dbConn.commit() 

dbConn.close() 

## FINISH LOGGING ## 

endTime = times.get_now_sql_datetime() 

runningTime = times.calculate_time_difference(startTime, endTime) 

log.info('-- FINISHED ATTEMPT TO RUN THE cl_utils.py AT %s (RUNTIME: %s) --' % 

(endTime, runningTime, )) 

 

return 

 

 

if __name__ == '__main__': 

main()