]> pere.pagekite.me Git - homepage.git/blob - blog/archive/2018/09/09.rss
Converted pages to actually temp site.
[homepage.git] / blog / archive / 2018 / 09 / 09.rss
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/'>
3 <channel>
4 <title>Petter Reinholdtsen - Entries from September 2018</title>
5 <description>Entries from September 2018</description>
6 <link>http://www.hungry.com/~pere/blog/</link>
7
8
9 <item>
10 <title>Valutakrambod - A python and bitcoin love story</title>
11 <link>http://www.hungry.com/~pere/blog/Valutakrambod___A_python_and_bitcoin_love_story.html</link>
12 <guid isPermaLink="true">http://www.hungry.com/~pere/blog/Valutakrambod___A_python_and_bitcoin_love_story.html</guid>
13 <pubDate>Sat, 29 Sep 2018 22:20:00 +0200</pubDate>
14 <description>&lt;p&gt;It would come as no surprise to anyone that I am interested in
15 bitcoins and virtual currencies. I&#39;ve been keeping an eye on virtual
16 currencies for many years, and it is part of the reason a few months
17 ago, I started writing a python library for collecting currency
18 exchange rates and trade on virtual currency exchanges. I decided to
19 name the end result valutakrambod, which perhaps can be translated to
20 small currency shop.&lt;/p&gt;
21
22 &lt;p&gt;The library uses the tornado python library to handle HTTP and
23 websocket connections, and provide a asynchronous system for
24 connecting to and tracking several services. The code is available
25 from
26 &lt;a href=&quot;http://github.com/petterreinholdtsen/valutakrambod&quot;&gt;github&lt;/a&gt;.&lt;/p&gt;
27
28 &lt;/p&gt;There are two example clients of the library. One is very simple and
29 list every updated buy/sell price received from the various services.
30 This code is started by running bin/btc-rates and call the client code
31 in valutakrambod/client.py. The simple client look like this:&lt;/p&gt;
32
33 &lt;p&gt;&lt;blockquote&gt;&lt;pre&gt;
34 import functools
35 import tornado.ioloop
36 import valutakrambod
37 class SimpleClient(object):
38 def __init__(self):
39 self.services = []
40 self.streams = []
41 pass
42 def newdata(self, service, pair, changed):
43 print(&quot;%-15s %s-%s: %8.3f %8.3f&quot; % (
44 service.servicename(),
45 pair[0],
46 pair[1],
47 service.rates[pair][&#39;ask&#39;],
48 service.rates[pair][&#39;bid&#39;])
49 )
50 async def refresh(self, service):
51 await service.fetchRates(service.wantedpairs)
52 def run(self):
53 self.ioloop = tornado.ioloop.IOLoop.current()
54 self.services = valutakrambod.service.knownServices()
55 for e in self.services:
56 service = e()
57 service.subscribe(self.newdata)
58 stream = service.websocket()
59 if stream:
60 self.streams.append(stream)
61 else:
62 # Fetch information from non-streaming services immediately
63 self.ioloop.call_later(len(self.services),
64 functools.partial(self.refresh, service))
65 # as well as regularly
66 service.periodicUpdate(60)
67 for stream in self.streams:
68 stream.connect()
69 try:
70 self.ioloop.start()
71 except KeyboardInterrupt:
72 print(&quot;Interrupted by keyboard, closing all connections.&quot;)
73 pass
74 for stream in self.streams:
75 stream.close()
76 &lt;/pre&gt;&lt;/blockquote&gt;&lt;/p&gt;
77
78 &lt;p&gt;The library client loops over all known &quot;public&quot; services,
79 initialises it, subscribes to any updates from the service, checks and
80 activates websocket streaming if the service provide it, and if no
81 streaming is supported, fetches information from the service and sets
82 up a periodic update every 60 seconds. The output from this client
83 can look like this:&lt;/p&gt;
84
85 &lt;p&gt;&lt;blockquote&gt;&lt;pre&gt;
86 Bl3p BTC-EUR: 5687.110 5653.690
87 Bl3p BTC-EUR: 5687.110 5653.690
88 Bl3p BTC-EUR: 5687.110 5653.690
89 Hitbtc BTC-USD: 6594.560 6593.690
90 Hitbtc BTC-USD: 6594.560 6593.690
91 Bl3p BTC-EUR: 5687.110 5653.690
92 Hitbtc BTC-USD: 6594.570 6593.690
93 Bitstamp EUR-USD: 1.159 1.154
94 Hitbtc BTC-USD: 6594.570 6593.690
95 Hitbtc BTC-USD: 6594.580 6593.690
96 Hitbtc BTC-USD: 6594.580 6593.690
97 Hitbtc BTC-USD: 6594.580 6593.690
98 Bl3p BTC-EUR: 5687.110 5653.690
99 Paymium BTC-EUR: 5680.000 5620.240
100 &lt;/pre&gt;&lt;/blockquote&gt;&lt;/p&gt;
101
102 &lt;p&gt;The exchange order book is tracked in addition to the best buy/sell
103 price, for those that need to know the details.&lt;/p&gt;
104
105 &lt;p&gt;The other example client is focusing on providing a curses view
106 with updated buy/sell prices as soon as they are received from the
107 services. This code is located in bin/btc-rates-curses and activated
108 by using the &#39;-c&#39; argument. Without the argument the &quot;curses&quot; output
109 is printed without using curses, which is useful for debugging. The
110 curses view look like this:&lt;/p&gt;
111
112 &lt;p&gt;&lt;blockquote&gt;&lt;pre&gt;
113 Name Pair Bid Ask Spr Ftcd Age
114 BitcoinsNorway BTCEUR 5591.8400 5711.0800 2.1% 16 nan 60
115 Bitfinex BTCEUR 5671.0000 5671.2000 0.0% 16 22 59
116 Bitmynt BTCEUR 5580.8000 5807.5200 3.9% 16 41 60
117 Bitpay BTCEUR 5663.2700 nan nan% 15 nan 60
118 Bitstamp BTCEUR 5664.8400 5676.5300 0.2% 0 1 1
119 Bl3p BTCEUR 5653.6900 5684.9400 0.5% 0 nan 19
120 Coinbase BTCEUR 5600.8200 5714.9000 2.0% 15 nan nan
121 Kraken BTCEUR 5670.1000 5670.2000 0.0% 14 17 60
122 Paymium BTCEUR 5620.0600 5680.0000 1.1% 1 7515 nan
123 BitcoinsNorway BTCNOK 52898.9700 54034.6100 2.1% 16 nan 60
124 Bitmynt BTCNOK 52960.3200 54031.1900 2.0% 16 41 60
125 Bitpay BTCNOK 53477.7833 nan nan% 16 nan 60
126 Coinbase BTCNOK 52990.3500 54063.0600 2.0% 15 nan nan
127 MiraiEx BTCNOK 52856.5300 54100.6000 2.3% 16 nan nan
128 BitcoinsNorway BTCUSD 6495.5300 6631.5400 2.1% 16 nan 60
129 Bitfinex BTCUSD 6590.6000 6590.7000 0.0% 16 23 57
130 Bitpay BTCUSD 6564.1300 nan nan% 15 nan 60
131 Bitstamp BTCUSD 6561.1400 6565.6200 0.1% 0 2 1
132 Coinbase BTCUSD 6504.0600 6635.9700 2.0% 14 nan 117
133 Gemini BTCUSD 6567.1300 6573.0700 0.1% 16 89 nan
134 Hitbtc+BTCUSD 6592.6200 6594.2100 0.0% 0 0 0
135 Kraken BTCUSD 6565.2000 6570.9000 0.1% 15 17 58
136 Exchangerates EURNOK 9.4665 9.4665 0.0% 16 107789 nan
137 Norgesbank EURNOK 9.4665 9.4665 0.0% 16 107789 nan
138 Bitstamp EURUSD 1.1537 1.1593 0.5% 4 5 1
139 Exchangerates EURUSD 1.1576 1.1576 0.0% 16 107789 nan
140 BitcoinsNorway LTCEUR 1.0000 49.0000 98.0% 16 nan nan
141 BitcoinsNorway LTCNOK 492.4800 503.7500 2.2% 16 nan 60
142 BitcoinsNorway LTCUSD 1.0221 49.0000 97.9% 15 nan nan
143 Norgesbank USDNOK 8.1777 8.1777 0.0% 16 107789 nan
144 &lt;/pre&gt;&lt;/blockquote&gt;&lt;/p&gt;
145
146 &lt;p&gt;The code for this client is too complex for a simple blog post, so
147 you will have to check out the git repository to figure out how it
148 work. What I can tell is how the three last numbers on each line
149 should be interpreted. The first is how many seconds ago information
150 was received from the service. The second is how long ago, according
151 to the service, the provided information was updated. The last is an
152 estimate on how often the buy/sell values change.&lt;/p&gt;
153
154 &lt;p&gt;If you find this library useful, or would like to improve it, I
155 would love to hear from you. Note that for some of the services I&#39;ve
156 implemented a trading API. It might be the topic of a future blog
157 post.&lt;/p&gt;
158
159 &lt;p&gt;As usual, if you use Bitcoin and want to show your support of my
160 activities, please send Bitcoin donations to my address
161 &lt;b&gt;&lt;a href=&quot;bitcoin:15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b&quot;&gt;15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b&lt;/a&gt;&lt;/b&gt;.&lt;/p&gt;
162 </description>
163 </item>
164
165 <item>
166 <title>VLC in Debian now can do bittorrent streaming</title>
167 <link>http://www.hungry.com/~pere/blog/VLC_in_Debian_now_can_do_bittorrent_streaming.html</link>
168 <guid isPermaLink="true">http://www.hungry.com/~pere/blog/VLC_in_Debian_now_can_do_bittorrent_streaming.html</guid>
169 <pubDate>Mon, 24 Sep 2018 21:20:00 +0200</pubDate>
170 <description>&lt;p&gt;Back in February, I got curious to see
171 &lt;a href=&quot;https://people.skolelinux.org/pere/blog/Using_VLC_to_stream_bittorrent_sources.html&quot;&gt;if
172 VLC now supported Bittorrent streaming&lt;/a&gt;. It did not, despite the
173 fact that the idea and code to handle such streaming had been floating
174 around for years. I did however find
175 &lt;a href=&quot;https://github.com/johang/vlc-bittorrent&quot;&gt;a standalone plugin
176 for VLC&lt;/a&gt; to do it, and half a year later I decided to wrap up the
177 plugin and get it into Debian. I uploaded it to NEW a few days ago,
178 and am very happy to report that it
179 &lt;a href=&quot;https://tracker.debian.org/pkg/vlc-plugin-bittorrent&quot;&gt;entered
180 Debian&lt;/a&gt; a few hours ago, and should be available in Debian/Unstable
181 tomorrow, and Debian/Testing in a few days.&lt;/p&gt;
182
183 &lt;p&gt;With the vlc-plugin-bittorrent package installed you should be able
184 to stream videos using a simple call to&lt;/p&gt;
185
186 &lt;p&gt;&lt;blockquote&gt;&lt;pre&gt;
187 vlc https://archive.org/download/TheGoat/TheGoat_archive.torrent
188 &lt;/pre&gt;&lt;/blockquote&gt;&lt;/p&gt;
189
190 &lt;/p&gt;It can handle magnet links too. Now if only native vlc had
191 bittorrent support. Then a lot more would be helping each other to
192 share public domain and creative commons movies. The plugin need some
193 stability work with seeking and picking the right file in a torrent
194 with many files, but is already usable. Please note that the plugin
195 is not removing downloaded files when vlc is stopped, so it can fill
196 up your disk if you are not careful. Have fun. :)&lt;/p&gt;
197
198 &lt;p&gt;I would love to get help maintaining this package. Get in touch if
199 you are interested.&lt;/p&gt;
200
201 &lt;p&gt;As usual, if you use Bitcoin and want to show your support of my
202 activities, please send Bitcoin donations to my address
203 &lt;b&gt;&lt;a href=&quot;bitcoin:15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b&quot;&gt;15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b&lt;/a&gt;&lt;/b&gt;.&lt;/p&gt;
204 </description>
205 </item>
206
207 <item>
208 <title>Using the Kodi API to play Youtube videos</title>
209 <link>http://www.hungry.com/~pere/blog/Using_the_Kodi_API_to_play_Youtube_videos.html</link>
210 <guid isPermaLink="true">http://www.hungry.com/~pere/blog/Using_the_Kodi_API_to_play_Youtube_videos.html</guid>
211 <pubDate>Sun, 2 Sep 2018 23:40:00 +0200</pubDate>
212 <description>&lt;p&gt;I continue to explore my Kodi installation, and today I wanted to
213 tell it to play a youtube URL I received in a chat, without having to
214 insert search terms using the on-screen keyboard. After searching the
215 web for API access to the Youtube plugin and testing a bit, I managed
216 to find a recipe that worked. If you got a kodi instance with its API
217 available from http://kodihost/jsonrpc, you can try the following to
218 have check out a nice cover band.&lt;/p&gt;
219
220 &lt;p&gt;&lt;blockquote&gt;&lt;pre&gt;curl --silent --header &#39;Content-Type: application/json&#39; \
221 --data-binary &#39;{ &quot;id&quot;: 1, &quot;jsonrpc&quot;: &quot;2.0&quot;, &quot;method&quot;: &quot;Player.Open&quot;,
222 &quot;params&quot;: {&quot;item&quot;: { &quot;file&quot;:
223 &quot;plugin://plugin.video.youtube/play/?video_id=LuRGVM9O0qg&quot; } } }&#39; \
224 http://projector.local/jsonrpc&lt;/pre&gt;&lt;/blockquote&gt;&lt;/p&gt;
225
226 &lt;p&gt;I&#39;ve extended kodi-stream program to take a video source as its
227 first argument. It can now handle direct video links, youtube links
228 and &#39;desktop&#39; to stream my desktop to Kodi. It is almost like a
229 Chromecast. :)&lt;/p&gt;
230
231 &lt;p&gt;As usual, if you use Bitcoin and want to show your support of my
232 activities, please send Bitcoin donations to my address
233 &lt;b&gt;&lt;a href=&quot;bitcoin:15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b&quot;&gt;15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b&lt;/a&gt;&lt;/b&gt;.&lt;/p&gt;
234 </description>
235 </item>
236
237 </channel>
238 </rss>