div class highlight pre span style color 408080 font-style italic codi

 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
<div class="highlight"><pre><span style="color: #408080; font-style: italic"># -*- coding: utf-8 -*-</span>
<span style="color: #408080; font-style: italic">#</span>
<span style="color: #408080; font-style: italic"># main.rb</span>
<span style="color: #408080; font-style: italic">#</span>
<span style="color: #408080; font-style: italic"># Copyright (C) 2009 burgua</span>
<span style="color: #408080; font-style: italic">#</span>
<span style="color: #408080; font-style: italic"># lashin.aleksey@gmail.com</span>
<span style="color: #408080; font-style: italic">#</span>
<span style="color: #408080; font-style: italic"># This program is free software; you can redistribute it and/or</span>
<span style="color: #408080; font-style: italic"># modify it under the terms of the GNU General Public License</span>
<span style="color: #408080; font-style: italic"># as published by the Free Software Foundation; either version 2</span>
<span style="color: #408080; font-style: italic"># of the License, or (at your option) any later version.</span>
<span style="color: #408080; font-style: italic"># This program is distributed in the hope that it will be useful,</span>
<span style="color: #408080; font-style: italic"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span style="color: #408080; font-style: italic"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span style="color: #408080; font-style: italic"># GNU General Public License for more details.</span>
<span style="color: #408080; font-style: italic">#</span>
<span style="color: #008000">require</span> <span style="color: #BA2121">&#39;rubygems&#39;</span>
<span style="color: #008000">require</span> <span style="color: #BA2121">&#39;plasma_applet&#39;</span>
<span style="color: #008000">require</span> <span style="color: #BA2121">&#39;curb&#39;</span>
<span style="color: #008000">require</span> <span style="color: #BA2121">&#39;md5&#39;</span>
<span style="color: #008000">require</span> <span style="color: #BA2121">&#39;iconv&#39;</span>
<span style="color: #008000; font-weight: bold">module</span> <span style="color: #0000FF; font-weight: bold">Vkontakte</span>
<span style="color: #008000; font-weight: bold">class</span> <span style="color: #0000FF; font-weight: bold">Main</span> <span style="color: #666666">&lt;</span> <span style="color: #880000">PlasmaScripting</span><span style="color: #666666">::</span><span style="color: #880000">Applet</span>
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">initialize</span> parent
<span style="color: #008000; font-weight: bold">super</span> parent
<span style="color: #008000; font-weight: bold">end</span>
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">init</span>
<span style="color: #008000">self</span><span style="color: #666666">.</span>has_configuration_interface <span style="color: #666666">=</span> <span style="color: #008000">false</span>
<span style="color: #008000">self</span><span style="color: #666666">.</span>aspect_ratio_mode <span style="color: #666666">=</span> <span style="color: #880000">Plasma</span><span style="color: #666666">::</span><span style="color: #880000">Square</span>
<span style="color: #008000">self</span><span style="color: #666666">.</span>background_hints <span style="color: #666666">=</span> <span style="color: #880000">Plasma</span><span style="color: #666666">::</span><span style="color: #880000">Applet</span><span style="color: #666666">.</span>DefaultBackground
layout <span style="color: #666666">=</span> <span style="color: #880000">Qt</span><span style="color: #666666">::</span><span style="color: #880000">GraphicsLinearLayout</span><span style="color: #666666">.</span>new <span style="color: #880000">Qt</span><span style="color: #666666">::</span><span style="color: #880000">Horizontal</span>, <span style="color: #008000">self</span>
label <span style="color: #666666">=</span> <span style="color: #880000">Plasma</span><span style="color: #666666">::</span><span style="color: #880000">Label</span><span style="color: #666666">.</span>new <span style="color: #008000">self</span>
layout<span style="color: #666666">.</span>add_item label
<span style="color: #008000">self</span><span style="color: #666666">.</span>layout <span style="color: #666666">=</span> layout
resize <span style="color: #666666">600</span>, <span style="color: #666666">1200</span>
label<span style="color: #666666">.</span>text <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;Wait a bit...&quot;</span>
<span style="color: #880000">Thread</span><span style="color: #666666">.</span>new { <span style="color: #008000; font-weight: bold">while</span> <span style="color: #008000">true</span>; label<span style="color: #666666">.</span>text<span style="color: #666666">=</span>getdata; <span style="color: #008000">sleep</span>(<span style="color: #666666">30</span>); <span style="color: #008000; font-weight: bold">end</span> }
<span style="color: #008000; font-weight: bold">end</span>
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">trymatch</span> (str,regex)
<span style="color: #008000; font-weight: bold">if</span> (str<span style="color: #666666">.</span>match(<span style="color: #BB6688">/</span><span style="color: #BB6688; font-weight: bold">#{</span>regex<span style="color: #BB6688; font-weight: bold">}</span><span style="color: #BB6688">/u</span>) <span style="color: #666666">==</span> <span style="color: #008000">nil</span>)
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #BA2121">&#39;0&#39;</span>
<span style="color: #008000; font-weight: bold">end</span>
str<span style="color: #666666">.</span>match(<span style="color: #BB6688">/</span><span style="color: #BB6688; font-weight: bold">#{</span>regex<span style="color: #BB6688; font-weight: bold">}</span><span style="color: #BB6688">/u</span>)<span style="color: #666666">[2]</span>
<span style="color: #008000; font-weight: bold">end</span>
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">filter</span> (data, label, tool)
str <span style="color: #666666">=</span> <span style="color: #BA2121">&#39;href=\&#39;&#39;</span><span style="color: #666666">+</span>tool<span style="color: #666666">+</span><span style="color: #BA2121">&#39;.php([A-Za-zА-Яа-я=\?\&#39;\s\d&amp;&gt;]*)\(&lt;b&gt;(.+)&lt;\/b&gt;&#39;</span>
rez <span style="color: #666666">=</span> trymatch(data,str)
<span style="color: #008000; font-weight: bold">if</span> (rez<span style="color: #666666">==</span><span style="color: #BA2121">&#39;0&#39;</span>)
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #BA2121">&#39;&#39;</span>
<span style="color: #008000; font-weight: bold">end</span>
<span style="color: #BA2121">&#39;&lt;tr&gt;&lt;td&gt;&#39;</span> <span style="color: #666666">+</span> label <span style="color: #666666">+</span> <span style="color: #BA2121">&quot;&lt;/td&gt;&lt;td&gt;&lt;b&gt;&quot;</span><span style="color: #666666">+</span> rez <span style="color: #666666">+</span> <span style="color: #BA2121">&#39;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&#39;</span>
<span style="color: #008000; font-weight: bold">end</span>
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">getdata</span>
<span style="color: #408080; font-style: italic"># get data from xml-file</span>
user <span style="color: #666666">=</span> {<span style="color: #BA2121">&#39;mid&#39;</span> <span style="color: #666666">=&gt;</span> <span style="color: #BA2121">&#39;******&#39;</span>, <span style="color: #BA2121">&#39;email&#39;</span> <span style="color: #666666">=&gt;</span> <span style="color: #BA2121">&#39;********&#39;</span>, <span style="color: #BA2121">&#39;pass&#39;</span> <span style="color: #666666">=&gt;</span> <span style="color: #880000">MD5</span><span style="color: #666666">.</span>md5(<span style="color: #BA2121">&#39;*********&#39;</span>)}
<span style="color: #408080; font-style: italic"># getted</span>
curl <span style="color: #666666">=</span> <span style="color: #880000">Curl</span><span style="color: #666666">::</span><span style="color: #880000">Easy</span><span style="color: #666666">.</span>new(<span style="color: #BA2121">&#39;http://vkontakte.ru/id872527&#39;</span>)
curl<span style="color: #666666">.</span>headers <span style="color: #666666">=</span> {<span style="color: #BA2121">&quot;User-Agent&quot;</span> <span style="color: #666666">=&gt;</span> <span style="color: #BA2121">&quot;Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.9.0.4) Gecko/2008112309 Iceweasel/3.0.4 (Debian-3.0.4-1)&quot;</span>,
<span style="color: #BA2121">&quot;Cookie&quot;</span> <span style="color: #666666">=&gt;</span> <span style="color: #BA2121">&quot;remixlang=0; remixchk=5; remixmid=</span><span style="color: #BB6688; font-weight: bold">#{</span>user<span style="color: #666666">[</span><span style="color: #BA2121">&#39;mid&#39;</span><span style="color: #666666">]</span><span style="color: #BB6688; font-weight: bold">}</span><span style="color: #BA2121">; remixemail=</span><span style="color: #BB6688; font-weight: bold">#{</span>user<span style="color: #666666">[</span><span style="color: #BA2121">&#39;email&#39;</span><span style="color: #666666">]</span><span style="color: #BB6688; font-weight: bold">}</span><span style="color: #BA2121">; remixpass=</span><span style="color: #BB6688; font-weight: bold">#{</span>user<span style="color: #666666">[</span><span style="color: #BA2121">&#39;pass&#39;</span><span style="color: #666666">]</span><span style="color: #BB6688; font-weight: bold">}</span><span style="color: #BA2121">; remixautobookmark=8&quot;</span>,
<span style="color: #BA2121">&quot;Referer&quot;</span> <span style="color: #666666">=&gt;</span> <span style="color: #BA2121">&quot;http://vkontakte.ru/&quot;</span>}
curl<span style="color: #666666">.</span>follow_location <span style="color: #666666">=</span> <span style="color: #008000">true</span>
curl<span style="color: #666666">.</span>perform
<span style="color: #408080; font-style: italic">#return &#39;0&#39;</span>
body <span style="color: #666666">=</span> curl<span style="color: #666666">.</span>unescape curl<span style="color: #666666">.</span>body_str
coder <span style="color: #666666">=</span> <span style="color: #880000">Iconv</span><span style="color: #666666">.</span>new(<span style="color: #BA2121">&quot;UTF-8&quot;</span>,<span style="color: #BA2121">&quot;WINDOWS-1251&quot;</span>)
body <span style="color: #666666">=</span> coder<span style="color: #666666">.</span>iconv(body)
result <span style="color: #666666">=</span> <span style="color: #BA2121">&#39;&lt;table&gt;&#39;</span>
result <span style="color: #666666">=</span> result <span style="color: #666666">+</span> filter(body,<span style="color: #BA2121">&#39;Friends&#39;</span>,<span style="color: #BA2121">&#39;friend&#39;</span>)
result <span style="color: #666666">=</span> result <span style="color: #666666">+</span> filter(body,<span style="color: #BA2121">&#39;Photos&#39;</span>,<span style="color: #BA2121">&#39;photos&#39;</span>)
result <span style="color: #666666">=</span> result <span style="color: #666666">+</span> filter(body,<span style="color: #BA2121">&#39;Videos&#39;</span>,<span style="color: #BA2121">&#39;video&#39;</span>)
result <span style="color: #666666">=</span> result <span style="color: #666666">+</span> filter(body,<span style="color: #BA2121">&#39;Messages&#39;</span>,<span style="color: #BA2121">&#39;mail&#39;</span>)
result <span style="color: #666666">=</span> result <span style="color: #666666">+</span> filter(body,<span style="color: #BA2121">&#39;Notes&#39;</span>,<span style="color: #BA2121">&#39;notes&#39;</span>)
result <span style="color: #666666">=</span> result <span style="color: #666666">+</span> filter(body,<span style="color: #BA2121">&#39;Groups&#39;</span>,<span style="color: #BA2121">&#39;groups&#39;</span>)
result <span style="color: #666666">=</span> result <span style="color: #666666">+</span> filter(body,<span style="color: #BA2121">&#39;Events&#39;</span>,<span style="color: #BA2121">&#39;events&#39;</span>)
result <span style="color: #666666">=</span> result <span style="color: #666666">+</span> filter(body,<span style="color: #BA2121">&#39;Matches&#39;</span>,<span style="color: #BA2121">&#39;matches&#39;</span>)
result <span style="color: #666666">=</span> result <span style="color: #666666">+</span> filter(body,<span style="color: #BA2121">&#39;Opinions&#39;</span>,<span style="color: #BA2121">&#39;opinions&#39;</span>)
result <span style="color: #666666">=</span> result <span style="color: #666666">+</span> filter(body,<span style="color: #BA2121">&#39;Questions&#39;</span>,<span style="color: #BA2121">&#39;questions&#39;</span>)
result <span style="color: #666666">=</span> result <span style="color: #666666">+</span> filter(body,<span style="color: #BA2121">&#39;Opinions&#39;</span>,<span style="color: #BA2121">&#39;opinions&#39;</span>)
result <span style="color: #666666">=</span> result <span style="color: #666666">+</span> <span style="color: #BA2121">&#39;&lt;/table&gt;&#39;</span>
<span style="color: #008000; font-weight: bold">end</span>
<span style="color: #008000; font-weight: bold">end</span>
<span style="color: #008000; font-weight: bold">end</span>
</pre></div>
<p style="padding: 0; margin: 2em 0 1em 0; font-size: 0.8em; color: #666;"><span style="padding: 0 1em; background-color: #f5f5f5;"> Colored with <a style="color: #333" href="http://dumpz.org">dumpz.org</a></span></p><p style="padding: 0; margin: 2em 0 1em 0; font-size: 0.8em; color: #666;"><span style="padding: 0 1em; background-color: #f5f5f5;"> Colored with <a style="color: #333" href="http://dumpz.org">dumpz.org</a></span></p>