forked from dinner/zuckonit.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gnote.vim.html
232 lines (182 loc) · 15.9 KB
/
gnote.vim.html
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
225
226
227
228
229
230
231
232
<!doctype html>
<html lang="">
<head>
<meta charset="utf-8"/>
<title>Send Your Note to Your Gmail - When I gone</title>
<meta name="author" content="Mocker">
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0">
<link href='http://fonts.googleapis.com/css?family=Droid+Sans:700,400|Droid+Sans+Mono' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="./theme/css/main.css" type="text/css" />
<!--[if lt IE 9]>
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link href="./" type="application/atom+xml" rel="alternate" title="When I gone ATOM Feed" />
</head>
<body>
<header class="clearfix" role="banner">
<div class="wrapper">
<h1 class="huge"><a href=".">When I gone</a></h1>
</div>
</header>
<div role="main" class="content clearfix">
<article>
<div class="post wrapper">
<h1>Send Your Note to Your Gmail</h1>
<h2>why I write such vim plugin</h2>
<hr />
<ul>
<li>ever I used a app called gnote on android,which is used for noting</li>
<li>these days I am learning something,I note in my vim</li>
<li>I wanna sync my note with some online account of myself</li>
<li>I love the products of google,that's why I choose gmail,not sth else</li>
</ul>
<hr />
<h2>part of code</h2>
<hr />
<h2>gnote.vim</h2>
<div class="codehilite"><pre><span class="k">if</span> !<span class="n">has</span><span class="p">(</span>"<span class="n">python</span>"<span class="p">)</span>
<span class="n">echo</span> "<span class="n">Error</span><span class="p">:</span><span class="n">no</span> <span class="n">python</span> <span class="n">supported</span>!"
<span class="n">finish</span>
<span class="n">endif</span>
<span class="k">function</span><span class="nf">! Gnote</span><span class="p">()</span><span class="w"></span>
<span class="n">python</span> <span class="o"><<</span> <span class="n">EOF</span>
<span class="n">import</span> <span class="n">imaplib</span>
<span class="n">import</span> <span class="n">time</span>
<span class="n">import</span> <span class="n">vim</span>
<span class="n">class</span> <span class="n">Gmail</span><span class="p">(</span><span class="n">object</span><span class="p">):</span>
<span class="n">IMAP_SERVER</span><span class="p">=</span> <span class="s">'imap.gmail.com'</span>
<span class="n">IMAP_PORT</span> <span class="p">=</span> 993
<span class="n">def</span> <span class="n">__init__</span><span class="p">(</span><span class="n">self</span><span class="p">,</span><span class="n">usr</span><span class="p">,</span><span class="n">pwd</span><span class="p">):</span>
<span class="n">self</span><span class="p">.</span><span class="n">usr</span> <span class="p">=</span> <span class="n">usr</span>
<span class="n">self</span><span class="p">.</span><span class="n">pwd</span> <span class="p">=</span> <span class="n">pwd</span>
<span class="n">self</span><span class="p">.</span><span class="n">hld</span> <span class="p">=</span> <span class="n">imaplib</span><span class="p">.</span><span class="n">IMAP4_SSL</span><span class="p">(</span><span class="n">self</span><span class="p">.</span><span class="n">IMAP_SERVER</span><span class="p">,</span><span class="n">self</span><span class="p">.</span><span class="n">IMAP_PORT</span><span class="p">)</span>
<span class="n">self</span><span class="p">.</span><span class="n">status</span> <span class="p">=</span> 0
<span class="n">def</span> <span class="n">login</span><span class="p">(</span><span class="n">self</span><span class="p">):</span>
<span class="n">rc</span><span class="p">,</span><span class="n">res</span> <span class="p">=</span> <span class="n">self</span><span class="p">.</span><span class="n">hld</span><span class="p">.</span><span class="n">login</span><span class="p">(</span><span class="n">self</span><span class="p">.</span><span class="n">usr</span><span class="p">,</span><span class="n">self</span><span class="p">.</span><span class="n">pwd</span><span class="p">)</span>
<span class="n">code</span> <span class="p">=</span> <span class="n">self</span><span class="p">.</span><span class="n">checkcode</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
<span class="k">if</span> <span class="n">code</span> <span class="o">==</span> <span class="n">True</span><span class="p">:</span>
<span class="n">self</span><span class="p">.</span><span class="n">status</span> <span class="p">=</span> 1
<span class="k">return</span> <span class="n">code</span>
<span class="n">def</span> <span class="n">logout</span><span class="p">(</span><span class="n">self</span><span class="p">):</span>
<span class="n">self</span><span class="p">.</span><span class="n">hld</span><span class="p">.</span><span class="n">logout</span><span class="p">()</span>
<span class="p">@</span><span class="n">staticmethod</span>
<span class="n">def</span> <span class="n">checkcode</span><span class="p">(</span><span class="n">code</span><span class="p">):</span>
<span class="n">code</span> <span class="p">=</span> <span class="n">str</span><span class="p">(</span><span class="n">code</span><span class="p">).</span><span class="n">upper</span><span class="p">()</span>
<span class="k">if</span> <span class="s">'OK'</span> <span class="n">in</span> <span class="n">code</span><span class="p">:</span>
<span class="k">return</span> <span class="n">True</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="n">False</span>
<span class="n">def</span> <span class="n">__del__</span><span class="p">(</span><span class="n">self</span><span class="p">):</span>
<span class="k">if</span> <span class="n">self</span><span class="p">.</span><span class="n">status</span> <span class="o">==</span> 1<span class="p">:</span>
<span class="n">self</span><span class="p">.</span><span class="n">hld</span><span class="p">.</span><span class="n">logout</span><span class="p">()</span>
<span class="n">def</span> <span class="n">addbox</span><span class="p">(</span><span class="n">self</span><span class="p">,</span><span class="n">mailbox</span><span class="p">):</span>
<span class="n">rc</span><span class="p">,</span><span class="n">res</span> <span class="p">=</span> <span class="n">self</span><span class="p">.</span><span class="n">hld</span><span class="p">.</span><span class="n">create</span><span class="p">(</span><span class="n">mailbox</span><span class="p">)</span>
<span class="n">code</span> <span class="p">=</span> <span class="n">self</span><span class="p">.</span><span class="n">checkcode</span><span class="p">(</span><span class="n">rc</span><span class="p">)</span>
<span class="k">return</span> <span class="n">code</span>
<span class="n">def</span> <span class="n">delbox</span><span class="p">(</span><span class="n">self</span><span class="p">,</span><span class="n">mailbox</span><span class="p">):</span>
<span class="n">rc</span><span class="p">,</span><span class="n">res</span> <span class="p">=</span> <span class="n">self</span><span class="p">.</span><span class="n">hld</span><span class="p">.</span><span class="n">delete</span><span class="p">(</span><span class="n">mailbox</span><span class="p">)</span>
<span class="n">code</span> <span class="p">=</span> <span class="n">self</span><span class="p">.</span><span class="n">checkcode</span><span class="p">(</span><span class="n">rc</span><span class="p">)</span>
<span class="k">return</span> <span class="n">code</span>
<span class="n">def</span> <span class="n">modbox</span><span class="p">(</span><span class="n">self</span><span class="p">,</span><span class="n">oldbox</span><span class="p">,</span><span class="n">newbox</span><span class="p">):</span>
<span class="n">rc</span><span class="p">,</span><span class="n">res</span> <span class="p">=</span> <span class="n">self</span><span class="p">.</span><span class="n">hld</span><span class="p">.</span><span class="n">rename</span><span class="p">(</span><span class="n">oldbox</span><span class="p">,</span><span class="n">newbox</span><span class="p">)</span>
<span class="n">code</span> <span class="p">=</span> <span class="n">self</span><span class="p">.</span><span class="n">checkcode</span><span class="p">(</span><span class="n">rc</span><span class="p">)</span>
<span class="k">return</span> <span class="n">code</span>
<span class="n">def</span> <span class="n">addnote</span><span class="p">(</span><span class="n">self</span><span class="p">,</span><span class="n">mailbox</span><span class="p">,</span><span class="n">content</span><span class="p">):</span>
<span class="n">t</span> <span class="p">=</span> <span class="n">time</span><span class="p">.</span><span class="n">strftime</span><span class="p">(</span>"<span class="c">%Y-%m-%d %H:%M:%S")</span>
<span class="n">content</span> <span class="p">=</span> "<span class="n">From</span><span class="p">:</span> <span class="c">%s\n\ntime:%s\n\n%s"%(self.usr,t,content)</span>
<span class="n">rc</span><span class="p">,</span><span class="n">res</span> <span class="p">=</span> <span class="n">self</span><span class="p">.</span><span class="n">hld</span><span class="p">.</span><span class="n">append</span><span class="p">(</span><span class="n">mailbox</span><span class="p">,</span><span class="n">None</span><span class="p">,</span><span class="n">None</span><span class="p">,</span><span class="n">content</span><span class="p">)</span>
<span class="n">code</span> <span class="p">=</span> <span class="n">self</span><span class="p">.</span><span class="n">checkcode</span><span class="p">(</span><span class="n">rc</span><span class="p">)</span>
<span class="k">return</span> <span class="n">code</span>
<span class="n">def</span> <span class="n">main</span><span class="p">():</span>
<span class="n">user</span> <span class="p">=</span> <span class="n">vim</span><span class="p">.</span><span class="n">eval</span><span class="p">(</span>"<span class="n">g</span><span class="p">:</span><span class="n">gnote_gmail_username</span>"<span class="p">)</span>
<span class="n">pawd</span> <span class="p">=</span> <span class="n">vim</span><span class="p">.</span><span class="n">eval</span><span class="p">(</span>"<span class="n">g</span><span class="p">:</span><span class="n">gnote_gmail_password</span>"<span class="p">)</span>
<span class="n">mailbox</span> <span class="p">=</span> <span class="s">''</span><span class="p">.</span><span class="n">join</span><span class="p">(</span><span class="n">vim</span><span class="p">.</span><span class="n">current</span><span class="p">.</span><span class="n">buffer</span><span class="p">[</span>0<span class="p">])</span>
<span class="n">gmail</span> <span class="p">=</span> <span class="n">Gmail</span><span class="p">(</span><span class="n">user</span><span class="p">,</span><span class="n">pawd</span><span class="p">)</span>
<span class="n">gmail</span><span class="p">.</span><span class="n">login</span><span class="p">()</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">gmail</span><span class="p">.</span><span class="n">addbox</span><span class="p">(</span><span class="n">mailbox</span><span class="p">)</span>
<span class="n">except</span><span class="p">:</span>
<span class="n">pass</span>
<span class="n">note</span> <span class="p">=</span> <span class="s">'\r\n'</span><span class="p">.</span><span class="n">join</span><span class="p">(</span><span class="n">vim</span><span class="p">.</span><span class="n">current</span><span class="p">.</span><span class="n">buffer</span><span class="p">[</span>1<span class="p">:])</span>
<span class="n">code</span> <span class="p">=</span> <span class="n">gmail</span><span class="p">.</span><span class="n">addnote</span><span class="p">(</span><span class="n">mailbox</span><span class="p">,</span><span class="n">note</span><span class="p">)</span>
<span class="k">if</span> <span class="n">code</span> <span class="o">==</span> <span class="n">True</span><span class="p">:</span>
<span class="n">print</span> <span class="s">'send to %s successful!'</span><span class="c">%mailbox</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">print</span> <span class="s">'send failed!'</span>
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">'__main__'</span><span class="p">:</span>
<span class="n">main</span><span class="p">()</span>
<span class="n">EOF</span>
<span class="n">endfunction</span>
</pre></div>
<h2>config in vim</h2>
<div class="codehilite"><pre><span class="n">let</span> <span class="n">g</span><span class="p">:</span><span class="n">gnote_gmail_username</span><span class="p">=</span>"<span class="n">your_gmail_username</span><span class="p">@</span><span class="n">gmail</span><span class="p">.</span><span class="n">com</span>"
<span class="n">let</span> <span class="n">g</span><span class="p">:</span><span class="n">gnote_gmail_password</span><span class="p">=</span>"<span class="n">your_gmail_password</span>"
</pre></div>
<hr />
<h2>in the future</h2>
<p>if you just take a look at my code of gnote.vim,you'll find I leave some<br />
interfaces for further functions,some functions may be useful.....maybe.</p>
<h2>usage</h2>
<hr />
<p>things look like this:<br />
you write your notes,diary or something else in vim,<br />
the first line is the note folder in gmail<br />
so,you'd better write sth meaningful in the first line<br />
</p>
<p>then..........<br />
</p>
<p>just :call Gnote()<br />
or just bind a key for that,things will look like easy - -*</p>
<hr />
<p>what's more?<br />
no more........<br />
</p>
<a href="https://twitter.com/share" class="twitter-share-button" data-via="" data-lang="en" data-size="large" data-related="">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
<div class="comments">
<h2>Comments !</h2>
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_identifier = "gnote.vim.html";
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://binlife.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
</div>
</div>
<div class="meta wrapper">
<time datetime="2012-10-21T00:00:00" pubdate>10月 21 2012</time>
<ul class="tag clearfix">
<li><a href="./category/vim.html">vim</a></li>
<li><a href="./tag/vim.html">vim</a></li>
<li><a href="./tag/python.html">python</a></li>
<li><a href="./tag/plugin.html">plugin</a></li>
</ul>
</div>
</article>
</div>
<footer class="clearfix">
<div class="wrapper pages">
<ul class="nav">
<li><a href="./archives.html">Archive</a></li>
</ul>
</div>
<div class="copy wrapper">
<ul class="social">
</ul>
<p role="contentinfo">© 2012 Mocker<br>
Proudly powered by <a href="http://alexis.notmyidea.org/pelican/">Pelican</a>.</p>
</div>
</footer>
<script>
var _gaq=[['_setAccount',''],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
</body>
</html>