Skip to content

Use WSPR database directly instead of web scraping - #7

Open
kareiva wants to merge 7 commits into
sm3ulc:masterfrom
kareiva:dev
Open

Use WSPR database directly instead of web scraping#7
kareiva wants to merge 7 commits into
sm3ulc:masterfrom
kareiva:dev

Conversation

@kareiva

@kareiva kareiva commented Nov 13, 2021

Copy link
Copy Markdown

Connect to the WsprDaeamon TimescaleDB directly and pull spots.
It's faster, gets more recent spots (bypass wsprnet cache).

This also moves the installation of python requirements over venv.

Connect to the WsprDaeamon TimescaleDB directly and pull spots.
It's faster, gets more recent spots (bypass wsprnet cache)

This also moves the installation of python requirements over venv

@domnantas domnantas left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Just a couple of questions since I'm not an expert in Python

Comment thread run.py
Comment on lines +17 to +19
def to_list(tuple):
return list(tuple)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? Isn't it possible to map(list, sqldata) without this wrapper function?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its way more clear and understandable, using this 2 line function. Because for those who don't know how does map works, this 2 line is easy to understand that it basically converts tuples to lists.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I struggle to understand how

def to_list(tuple):
    return list(tuple)

tabledata = map(to_list, sqldata)

is more clear than

tabledata = map(list, sqldata)

it's just a tiny abstraction and you still need to understand how map works. Don't think this is worth discussing, both approaches work fine :)

@Alperencode Alperencode Nov 17, 2021

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First code that you write is not a usage of functions in python
Normal usage is:

def to_list(tuple):
    return list(tuple)

tabledata = to_list(sqldata) 

And in that way you don't need to use map(). But as you mentioned, yeah both approaches work fine but this one is easier to understand for python developers.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, noticed that just now. Probably map is taking just the function name, didn't need to use it before, my bad mate.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Javascript and functional programming, it is common to see something like this

[1, 2, 3].map(toString); // toString is a function
// which basically translates to
[toString(1), toString(2), toString(3)]

Cheers!

Comment thread run.py
Comment on lines +24 to +26
except psycopg2.OperationalError as err:
logging.error("PostgreSQL connect error: " + err)
conn = None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too familiar with Python, but isn't it necessary to return in the exception handler, so the conn.cursor() on the next line would not be executed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants