RE: [ENG/ITA] Python and Hive: Learning from Other Hiveans!

You are viewing a single comment's thread:

That's how I taught myself.

Really!? You are so good and you have done all by yourself? Dang, that's beyond motivating 😅

omg, you've ruined it! 😅

I know 🤣 but don't worry, the comments are there only for the sake of this post: I promise I won't put any when I'll use your code in my scripts ahahah

So instead of me explaining, you had a chance to experience it happening and come to your own conclusions. Which was the plan.

I love your approach, tbh: it challenges the reader to actively learn and this is by far more efficient than just reading an explanation. By trying myself your code I was able to ask myself why you did something, look for an answer by using my brain and than, finally, understand what was doing what and, most importantly, why.

Sessions/Requests are still a bit obscure for me, though, but I can't hope to understand everything immediately, so I'll keep checking the docs and experimenting with different API call to strengthen my knowledge.



0
0
0.000
8 comments
avatar

Really!? You are so good and you have done all by yourself? Dang, that's beyond motivating 😅

Yes.
I am not even good.
The stuff I build is far from industry standard.

What seems impressive now, will look like a joke another month in.
Once you've built a few things, you'll notice.
Repetition -> learning.

Sometimes I do totally unrelated stuff and suddenly I understand something that I tried weeks ago...

Sessions/Requests are still a bit obscure for me, though, but I can't hope to understand everything immediately, so I'll keep checking the docs and experimenting with different API call to strengthen my knowledge.

Yeah... I can tell by your comments on the code, that it hasn't 'clicked' for you.
Thing is: that has nothing to do with HIVE, but you just need more practice with Python and code in general.
...and there are enough Python tutorials out there.
If something isn't clear, I am happy to help, but I can't also try to teach Python in my tutorials.

That with statement is very pythonic and it's powerful.
Other languages don't even have that concept...

For now: Please trust me, it's the cleanest way to go about it.
I use it for reasons and they will become clearer when I continue.
It's worth exploring...

I love your approach, tbh: it challenges the reader to actively learn and this is by far more efficient than just reading an explanation.

That's it. Feels good that it worked for you.
But it really only works, when people actually try to use it.
Tagging @slobberchops for good measure here.

0
0
0.000
avatar

I can tell by your comments on the code, that it hasn't 'clicked' for you.

Still far from clicking, but slowly I'll get it :)

Please trust me

100% trust! I know that "with" is very powerful and I was using it to open a file, but from your code I learned that it can do much more, so yup, just from a few lines of yours thare's a lot of stuff which are very much worth exploring!

If something isn't clear, I am happy to help, but I can't also try to teach Python in my tutorials.

Your comments and posts are already way much more than what I was hoping to find :)

0
0
0.000
avatar
(Edited)

I know that "with" is very powerful and I was using it to open a file

...and close it.

with keeps any session (writing files, accessing databases, http sessions) open and closes it, too. This leads to cleaner structure and cleaner code.
(The other way would be using open() and close() functions, which can lead to all sorts of trouble)

btw did you manage to use condenser's get_accounts function?

0
0
0.000
avatar
(Edited)

I was aware that it open and close a file, but I didn't know it could be used for different tasks, like databases and http sessions: a knowledge worth remembering... and mastering :)

btw did you manage to use condenser's get_accounts function?

Today I tried a bit the condenser_api.get_discussions_by_author_before_date, because I needed to see what info were submitted when publishing a post... and after that I started experimenting a bit 😅

def get_discussions_before_date(url, num, session: requests.Session):
    data = f'{{"jsonrpc":"2.0", "method":"condenser_api.get_discussions_by_author_before_date", "params":["arc7icwolf","","2024-09-12T22:49:43",{num}], "id":1}}'
    response = get_response(data, url, session)
    discussions = response.json()['result']
    reputation_list = []
    for discussion in discussions:
        reputation = discussion['author_reputation']
        if reputation not in reputation_list:
            reputation_list.append(reputation)
    return reputation_list

And here is when I found that my reputation hasn't changed with the last 100 posts I published 😂

EDIT: unless I made a mistake, because now I'm trying to change the date and it keeps giving me the same results as before:

import requests

def get_response(data, url, session: requests.Session):
    request = requests.Request("POST", url=url, data=data).prepare()
    response = session.send(request, allow_redirects=False)
    return response

def get_discussions_before_date(url, num):
    with requests.Session() as session:
        data = f'{{"jsonrpc":"2.0", "method":"condenser_api.get_discussions_by_author_before_date", "params":["arc7icwolf","","2024-07-29T12:23:09",{num}], "id":1}}'
        response = get_response(data, url, session)
        discussions = response.json()['result']
        reputation_list = []
        for discussion in discussions:
            print(discussion)
            reputation = discussion['title']
            if reputation not in reputation_list:
                reputation_list.append(reputation)
        return reputation_list


def main():
    url = "https://api.deathwing.me"
    num = 3
    rep_list = get_discussions_before_date(url, num)
    print(rep_list)


if __name__ == "__main__":

    main()

No matter what date I set, I always see the data and title about my last 3 posts... I guess I'll try to understand what I messed up tomorrow after a good sleep 😴

0
0
0.000
avatar

Condenser provides 'higher level' information. The further you deviate from the core functions of Hive, the more complicated (and unreliable) it gets.
Reputation for example is abstracted. It never was a core feature of Hive, but was built on top of it.

And here is when I found that my reputation hasn't changed with the last 100 posts I published 😂

Whenever you get a vote (up or down) it affects your reputation.
So yeah, something went wrong.

I am not familiar with all calls in the documentation.
I have never touched get_discussions_by_author_before_date
There's also no guarantee that the calls are properly documented and I raged about that a while ago:
https://peakd.com/dev/@felixxx/hive-api-reference-incomplete
I have since been told that the documentation is incomplete on purpose, because the higher level (hivemind) stuff, will be abandoned in the future in favor of a HAF infrastructure.

I am pretty sure there is no extra table that saves how high your reputation was at a given time. That would be a very long database table that makes an entry after every vote you ever received and that for every user... too much data for too little benefit...

I could look into the above call more closely, depending on how important it is for you.

Generally, I'd say: stay away from get_discussion and anything reputation for now. They are soft.
block_api, account_api are core features and the most reliable...

0
0
0.000
avatar

I have since been told that the documentation is incomplete on purpose

What an unusual purpose LOL also considering that I guess that this situation is going on since a long time, and this doesn't sound like something which could help increase adoption...

I could look into the above call more closely, depending on how important it is for you.

Don't worry, I chose that key only to see if was able to access it, but I could have chosen a different one! oc I had to choose one that wasn't working properly among all the available keys 🤣

Generally, I'd say: stay away from get_discussion and anything reputation for now. They are soft.

Gotcha!

0
0
0.000
avatar

Well...

I actually went ahead an wrote a whole post about it...

0
0
0.000
avatar

Already seen and upvoted! :) Happy to see you posting more snippets and useful tips! As soon as I can I will read again it and use it to make more progress with my coding.

0
0
0.000