<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alex D&#39;Ambra on Medium]]></title>
        <description><![CDATA[Stories by Alex D&#39;Ambra on Medium]]></description>
        <link>https://medium.com/@alexdambra?source=rss-12a72276194d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8VqUVXeKvJcGVmJME1UcTg.png</url>
            <title>Stories by Alex D&amp;#39;Ambra on Medium</title>
            <link>https://medium.com/@alexdambra?source=rss-12a72276194d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 03:34:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alexdambra/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to get Aussie property price guides using Python & the Domain API]]></title>
            <link>https://medium.com/@alexdambra/how-to-get-aussie-property-price-guides-using-python-the-domain-api-afe871efac96?source=rss-12a72276194d------2</link>
            <guid isPermaLink="false">https://medium.com/p/afe871efac96</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[real-estate]]></category>
            <dc:creator><![CDATA[Alex D'Ambra]]></dc:creator>
            <pubDate>Tue, 12 Feb 2019 12:02:30 GMT</pubDate>
            <atom:updated>2019-02-12T21:57:44.555Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’re an Australian you probably spend a lot of your time reading about, hearing about, or talking about property. It’s a national pastime. So most Aussies are familiar with Domain, one of the big two real estate websites. One of my biggest frustrations with real estate listings is when no price guide is listed by the agent. What’s more annoying is that I know a price or price range has always been provided by the agent, because the search engine needs to be able to filter by a user’s minimum and maximum prices.</p><p>For example let’s take this <a href="https://www.domain.com.au/132a-prince-edward-avenue-earlwood-nsw-2206-2014925785">listing </a>for a house in Sydney’s inner west suburb of Earlwood:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*52BW5oSwcVq6YsdERJRO2w.png" /><figcaption>Why no price guide?!!?</figcaption></figure><p>No price guide is provided. But if I search for houses with a max of $1 million there are no results. So I know the price range for this house is at least $1 million:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q22P5Pg1dkE4JNUpUlqszw.png" /><figcaption>Lol @ Sydney house prices</figcaption></figure><p>If I keep increasing my max price I will eventually see this in my search results. At $1.8m I get a hit:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*zni0ULf1R_J9DnWI_Beu6w.png" /><figcaption>Bingo!</figcaption></figure><p>So now I can get an actual feel for what price range the agent/vendor is pitching this property at. Great. But what a painful, time-consuming process right? So I thought surely we can use Python to automate this!</p><p>This is when I decided to get a <a href="https://developer.domain.com.au/">Domain developer account</a> to take a look at their APIs. Firstly I tried doing a <a href="https://developer.domain.com.au/docs/endpoints/listings/listings_get">simple request to retrieve the listing info</a> for a given property to see if the price guide would be in there. No luck. So instead I wrote a script over a weekend to basically automate the process of searching through different maximum prices to get a guide. Now I could go through the whole process here on Medium but this time I used <a href="https://colab.research.google.com/">Google’s Colaboratory</a>, a free Jupyter notebook environment that requires no setup and runs entirely in the cloud. Take a look at my <a href="https://colab.research.google.com/drive/16wg0VWPim1-dwt7W8jZuJrqFRMrW8iQ0">notebook </a>where I’ve added a bunch of commentary and instructions in the markdown. Download the whole notebook or the .py and go nuts. Hope you find this useful, even if it’s just to help with your property searches.</p><p>The best projects are the ones that solve your real life annoyances. That’s why learning Python has been a lot of fun. It’s really flexible and easy to get started and start solving actual problems with. I often see the book<a href="https://automatetheboringstuff.com/"> Automate the Boring Stuff with Python</a> recommended for these reasons. I haven’t read it myself but it may be worth a look.</p><p>Good luck with your Python exploits and your house hunting!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afe871efac96" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting your reading history out of Pocket using Python]]></title>
            <link>https://medium.com/@alexdambra/getting-your-reading-history-out-of-pocket-using-python-b4253dbe865c?source=rss-12a72276194d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4253dbe865c</guid>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pocket]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[json]]></category>
            <dc:creator><![CDATA[Alex D'Ambra]]></dc:creator>
            <pubDate>Tue, 13 Mar 2018 23:50:33 GMT</pubDate>
            <atom:updated>2020-05-12T04:27:05.765Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kPKykXB1Bog-f7R-." /><figcaption>Photo by <a href="https://unsplash.com/@brandi1?utm_source=medium&amp;utm_medium=referral">Brandi Redd</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I’ve been using <a href="https://getpocket.com/">Pocket</a> for many years to collate all the articles, blog posts, recipes, etcI’ve found online. I decided it would be interesting to get my reading history out of Pocket so I could do some analysis and visualisation on the data.</p><p>Within Pocket there is a basic <a href="https://getpocket.com/export">HTML export function</a>, and there are also several <a href="https://ifttt.com/pocket">IFTTT </a>recipes that you could use to back up your articles to Google Drive or Evernote. However I wanted to challenge myself to start using Python to query data from web APIs and manipulate the data types they return.</p><p>Here is how I went about it. <strong>Note</strong>: The following code uses Python 3.x.</p><p>First you’ll need to <a href="https://getpocket.com/developer/">create an “application”</a> to access the Pocket developer API. Principally for this exercise you’ll only need “Retrieve” permissions. I created an application called <em>AlexAnalysis </em>and I was assigned a 30 character consumer key.</p><p>Now we’re ready to get into Python! I would suggest using a <a href="http://jupyter.org/">Jupyter notebook</a> for this type of exercise.</p><p>First let’s import the libraries we’ll need for this exercise.</p><pre>import json<br>import pandas as pd<br>import requests<br>from urllib.parse import urlencode<br>from urllib.request import Request, urlopen</pre><p>I’m going to show a couple of methods for posting requests to the API. One method utilises Python’s native <strong>urllib</strong>, and the other uses the excellent <a href="http://docs.python-requests.org/en/master/"><strong>Requests </strong></a>library which makes things very easy.</p><p>Let’s begin with posting a request to the Pocket API to get a temporary <strong>Request Token</strong>. Replace <em>your_consumer_key </em>with the key you received from Pocket. We’ll be using Python’s urllib library:</p><pre># POST request for token</pre><pre>url = &#39;<a href="https://getpocket.com/v3/oauth/request&#39;">https://getpocket.com/v3/oauth/request&#39;</a> # Set destination URL here</pre><pre>post_fields = {&quot;consumer_key&quot;:&quot;<strong>your_consumer_key</strong>&quot;,&quot;redirect_uri&quot;:&quot;<a href="http://www.google.com/">http://www.google.com</a>&quot;}   # Set POST fields here</pre><pre>request = Request(url, urlencode(post_fields).encode())<br>json = urlopen(request).read().decode()<br>print(json)</pre><p>You’ll receive a response with the request token. Make note of this.</p><p>Next you need to create a URL and visit it in your browser:</p><pre>https://getpocket.com/auth/authorize?request_token=<strong>your_request_token</strong>&amp;redirect_uri=<a href="http://www.google.com/">http://www.google.com</a>&quot;</pre><p>You’ll be prompted to login to Pocket and authorise your app.</p><p>Next you’ll need to issue another POST request to get an access token using your consumer_key and your request token:</p><pre># POST request an access token</pre><pre>url = &#39;<a href="https://getpocket.com/v3/oauth/authorize&#39;">https://getpocket.com/v3/oauth/authorize&#39;</a> # Set destination URL here<br>post_fields = {&quot;consumer_key&quot;:&quot;<strong>your_consumer_key</strong>&quot;,&quot;code&quot;:&quot;<strong>your_request_token</strong>}  # Set POST fields here</pre><pre>request = Request(url, urlencode(post_fields).encode())<br>json = urlopen(request).read().decode()<br>print(json)</pre><p>You’ll receive a response with an <strong>access token</strong>. Make note of this as it’s what you’ll use to make authenticated requests against the Pocket API from now on.</p><p>Now we can start making GET requests against the API to get data out. For the next request I’m going to use the <strong>Requests </strong>library I mentioned earlier instead of urllib. It’s an alternative to urllib and it’s super easy to use.</p><pre># GET request for data in JSON format</pre><pre>parameters = {“consumer_key”:”<strong>your_consumer_key</strong>&quot;,”access_token”:”<strong>your_access_token</strong>”}</pre><pre>response = requests.get(“<a href="https://getpocket.com/v3/get">https://getpocket.com/v3/get</a>&quot;, params=parameters)</pre><p>You’ll see in the above that I have fed in the parameters for my consumer key and my access token. You can also feed in some other parameters:</p><ul><li><em>”count”:”10</em>&quot; This will limit the number of results returned to the number specified, in this case the first 10 articles.</li><li><em>“detailType”:”complete”</em> This will give you all data available including tags (very useful). In this example I’ve kept it simple and just retrieved the standard response.</li><li>The full list of optional parameters is detailed <a href="https://getpocket.com/developer/docs/v3/retrieve">here</a>.</li></ul><p>OK, now you’ll receive a response in the form of some JSON data that will look like this:</p><pre>{&#39;complete&#39;: 1,<br> &#39;error&#39;: None,<br> &#39;list&#39;: {&#39;1992211110&#39;: {&#39;excerpt&#39;: &#39;What a splendid era this was going to be, with one remaining superpower spreading capitalism and liberal democracy around the world. Instead, democracy and capitalism seem increasingly incompatible.&#39;,<br>   &#39;favorite&#39;: &#39;0&#39;,<br>   &#39;given_title&#39;: &#39;&#39;,<br>   &#39;given_url&#39;: &#39;http://nyrevinc.cmail20.com/t/y-l-klpdut-jduhlyklkl-d/&#39;,<br>   &#39;has_image&#39;: &#39;0&#39;,<br>   &#39;has_video&#39;: &#39;0&#39;,<br>   &#39;is_article&#39;: &#39;1&#39;,<br>   &#39;is_index&#39;: &#39;0&#39;,<br>   &#39;item_id&#39;: &#39;1992211110&#39;,<br>   &#39;resolved_id&#39;: &#39;1977788178&#39;,<br>   &#39;resolved_title&#39;: &#39;The Man from Red Vienna&#39;,<br>   &#39;resolved_url&#39;: &#39;http://www.nybooks.com/articles/2017/12/21/karl-polanyi-man-from-red-vienna/&#39;,<br>   &#39;sort_id&#39;: 8,<br>   &#39;status&#39;: &#39;0&#39;,<br>   &#39;time_added&#39;: &#39;1520132694&#39;,<br>   &#39;time_favorited&#39;: &#39;0&#39;,<br>   &#39;time_read&#39;: &#39;0&#39;,<br>   &#39;time_updated&#39;: &#39;1520140351&#39;,<br>   &#39;word_count&#39;: &#39;4009&#39;},</pre><p>If you’re familiar with JSON you’ll see that what we’re after here is an object called <strong>List</strong>. It has info like title, URL, word count, time read, whether or not I’ve favorited it, etc.</p><p>To allow us to do some analysis let’s get this JSON object into a <a href="https://pandas.pydata.org/"><strong>pandas </strong></a>dataframe:</p><pre>df = pd.DataFrame(response.json()[‘list’])</pre><p>The result will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*_-Nzd1zla5KoDNwpdvtFnA.png" /></figure><p>We probably want to swap the columns and rows so that the id runs down the rows and the attributes form columns.</p><p>Let’s transpose:</p><pre>df=df.transpose()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*HgqykSc3IdvcduwsSN2TUA.png" /></figure><p>Now we have our data in a pandas dataframe we can start doing some analysis and begin to visualise the data. This will form the basis of my next post.</p><p>I found this to be a great exercise in python, pandas, JSON, web APIs — with a pretty easy learning curve. Good luck!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4253dbe865c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>