-
Notifications
You must be signed in to change notification settings - Fork 0
/
laFb.py
executable file
·153 lines (131 loc) · 4.06 KB
/
laFb.py
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
from __future__ import unicode_literals
#from urllib import urlretrieve
#import imp
import os
import sys
import fbconsole
import unicodedata
import textwrap
#urlretrieve('https://raw.github.com/facebook/fbconsole/master/src/fbconsole.py', '.fbconsole.py')
#fb = imp.load_source('fb', '.fbconsole.py')
fbconsole.AUTH_SCOPE = ['publish_stream','publish_checkins','read_stream']
fbconsole.authenticate()
CODE={
'ENDC':0, # RESET COLOR
'BOLD':1,
'UNDERLINE':4,
'BLINK':5,
'INVERT':7,
'CONCEALD':8,
'STRIKE':9,
'GREY30':90,
'GREY40':2,
'GREY65':37,
'GREY70':97,
'GREY20_BG':40,
'GREY33_BG':100,
'GREY80_BG':47,
'GREY93_BG':107,
'DARK_RED':31,
'RED':91,
'RED_BG':41,
'LIGHT_RED_BG':101,
'DARK_YELLOW':33,
'YELLOW':93,
'YELLOW_BG':43,
'LIGHT_YELLOW_BG':103,
'DARK_BLUE':34,
'BLUE':94,
'BLUE_BG':44,
'LIGHT_BLUE_BG':104,
'DARK_MAGENTA':35,
'PURPLE':95,
'MAGENTA_BG':45,
'LIGHT_PURPLE_BG':105,
'DARK_CYAN':36,
'AUQA':96,
'CYAN_BG':46,
'LIGHT_AUQA_BG':106,
'DARK_GREEN':32,
'GREEN':92,
'GREEN_BG':42,
'LIGHT_GREEN_BG':102,
'BLACK':30,
}
def termcode(num):
return '\033[%sm'%num
def colorstr(astr,color):
return termcode(CODE[color])+astr+termcode(CODE['ENDC'])
def run(program, obj):
pid = os.fork()
if not pid:
os.execvp(program, obj)
return os.wait()[0]
ri=0
rMax=10
defMsgs = 'no message'
defComments = 'no comments'
defFrom = 'nowhere'
defData = 'no data'
defPic = 'no pic'
subFolder = "home"
if len(sys.argv) == 1:
print "laFb.py <option> <para1> <para2...>"
print "<option> <para1> <para2> | describe"
print "p message | update your fb status"
print "r counts | read counts from your fb home page"
exit()
#==== input control ====
if len(sys.argv) >= 3:
if len(sys.argv[2]) == 0:
rMax = 10
else:
rMax = int(sys.argv[2])
if len(sys.argv) >= 4:
if len(sys.argv[3]) == 0:
subFolder="home"
elif sys.argv[3] == 'h':
subFolder="home"
elif sys.argv[3] == 'm':
subFolder="feed"
else:
subFolder="home"
#==== input control ====
if sys.argv[1] == 'p':
status = fbconsole.post("/me/feed", {"message":sys.argv[2]})
elif sys.argv[1] == 'r':
for post in fbconsole.iter_pages(fbconsole.get('/me/'+subFolder)):
#==== MESSAGE ====
print ''
dedented_text = textwrap.dedent(post.get('message',defMsgs)).strip()
print colorstr(textwrap.fill(dedented_text,width=40, initial_indent=' '+post.get('from',defMsgs).get('name',defMsgs)+":", subsequent_indent=' '),'YELLOW')
#print post.get('comments',defComments)
#print len(post.get('comments',defComments))
#print post.get('comments',defComments)
if post.get('comments',defComments).get('count',defMsgs) != 0:
#==== PICTURE ====
if post.get('picture',defPic)!='no pic':
#paraList = [' ','--term-width','--colors',post.get('picture',defPic)]
#run('jp2p',paraList)
paraList = [' ',post.get('picture',defPic),'-s','-o','tmp.jpg']
print paraList
run('curl',paraList);
paraList2 = [' ','tmp.jpg','-colorspace','Gray','tmpgray.jpg']
run('convert',paraList2)
paraList3 = [' ','tmpgray.jpg','-blur','5','tmpblur.jpg']
run('convert',paraList3)
paraList4 = [' ','tmpblur.jpg','-edge','6','tmpEdge.jpg']
run('convert',paraList4)
paraList5 = [' ','--term-width','tmpEdge.jpg']
run('jp2a',paraList5)
#print type(post.get('comments',defComments))
for reply in post.get('comments',defComments).get('data',defMsgs):
#print type(reply)
if type(reply) != unicode:
dedented_textC = textwrap.dedent(reply.get('message',defMsgs))
print textwrap.fill(dedented_textC,width=40, initial_indent=' >'+reply.get('from',defMsgs).get('name',defMsgs)+":", subsequent_indent=' ')
#for comments in post.get('comments',defComments):
# print comments.get('id',defFrom)
ri+=1
if ri == rMax:
break