RE: [ENG/ITA] Python & Hive: My Scripts are Ready! My First Project is Completed :)
You are viewing a single comment's thread:
Hi!
One thing that you could consider, is to instead of checking one block at a time, and waiting a full minute in between, you could fetch multiple blocks in one go, then immediately process them. This could be way faster if some of the blocks don't contain posts relevant to your query.
Something like this:
for block_num in range(last_block_num, last_hive_block_num):
ops = get_ops_in_block(block_num, url, session)
post_list.extend(get_post(ops))
Hope it helps. !WINE
0
0
0.000
If I haven't done something wrong - which I may have done 😅 - the 60 seconds delay should only be triggered when the current block I just processed is the same as the current last Hive block. So there shouldn't be any delay when I'm checking older blocks - as in this case there isn't the risk of checking a block which has still to be produced by the chain.
But beside that, my script isn't as fast as I hoped, so your suggestion may help it checking even older blocks faster, right? I have no access to the code right now, but as soon as I come back I'm going to implement it and see if I can make it works!
Many thanks!!!
!LUV
@gamer00, @arc7icwolf(1/4) sent you LUV. | tools | discord | community | HiveWiki | <>< daily
I'm so tired I have no idea what I've done, but working on your suggestion I was able to improve the script, which is now much faster (around 3 times faster I think!).
This is the part I changed:
Probably it could have been implemented better, but I'm still very happy of the improvement!
Thanks for your awesome suggestion :)
EDIT: made a slight improvement!
!PIZZA
You are now successfully processing multiple blocks in one go, instead of fetching them one-by-one and processing them separately. The minute-long pause sort of added insult to injury and made it look like the script made even less progress.
Btw. I like the idea of a dynamic sleep time based on the difference in block numbers! How'd you come up with that? I hate to admit I wouldn't have thought of something like that.
About your original script...
I had to add some print statements to see what it did though. I think seeing on-screen what the script does is helpful in many cases to understand what is going on.
Since I saw your script wrote logs, I also put 'tail -f' to follow them, but it looks like I didn't catch any Italian posts this time as nothing much got written on them.
I wrote a really long rant about double conversions from:
...to only using Regex to strip out Markdown elements:
...because it would've been faster and removed the need for extra libraries, but then I realized Hive posts quite often contain html tags. Even I use them quite often to make my posts look better. So maybe it's important to keep the double conversions after all.
So here I would've been completely off the base again.
Oh, btw, my editor (I currently use Neovim) complained about this line in your code:
The warning was: "Avoid equality comparisons to 'False'; use
if not valid_language:
for false checks"The problem is that you made a comparison to a True/False boolean, and I guess it is not considered proper Python code. So the corrected code is like the warning said:
Well... I think I might have to go through the other script too. This one was fun.
My biggest concern was to start checking hive blocks before they even existed, so I asked ChatGPT - yeah, I often ask it a lot of questions !LOL - if I could use the range function dinamically, switching between a default amount and a max amount, whichever was lower. And then it suggested me to use "min()" to check what the lower among the two was... this is how it went 😅
Totally possible! For testing purpose I set the language to "en", reduce the words to a very few and often switch from posts to comments.
I came up with the solution because of that, as I soon realized I was counting a lot of strings that weren't words, so I looked for a solution... and Beautiful Soup is such a cool name ahahah
Well, I'm still happy that the rest is considered Python ahahah
Thanks for this correction! It makes totally sense and I have no idea why I keep forgetting things I know... ahhhh it's exactly as you said in the other comment: code is an illusion!
lolztoken.com
I still wonder what she saw in him.
Credit: reddit
@gamer00, I sent you an $LOLZ on behalf of arc7icwolf
(5/10)
NEW: Join LOLZ's Daily Earn and Burn Contest and win $LOLZ
ChatGPT seems to be a very good teacher, although quite often it just slams me with the complete solution and doesn't let me think for myself. I don't know what to think about that. But I guess it does sometimes come up with quite elegant solutions. A friend of mine once said that with ChatGPT, you are not really chatting with a computer, but the rest of the world. It's like you are chatting with the knowledge of everyone, so that's why it comes up with interesting solutions too.
Oh, I will try changing the language to see whether I can catch any english posts with the script, yes that might be a workable idea! :) Btw. the script needs some error-checking:
Since I have no idea what this error is trying to tell me, I asked ChatGPT, and since its answer was quite long, I'll condense it here:
The error
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
occurs when the response received from the API is empty or not a valid JSON.I guess that for one reason or another, the server borked the output, and the script didn't quite know what to do.
These were the suggested ways to fix it:
get_ops_in_block
function to handle the case where the response is empty or not JSON.In case you want to be adventurous, check my script for error handling. If you get lost, ask ChatGPT and it will come up with an excellent example that's the complete answer and leaves nothing to actually learn. ;)
Personally, if I am being adventurous, I like to pose my questions in a way that forces the bot to give a detailed explanation of how to fix the problem without showing me any code. Usually I just get frustrated and cheat again. But maybe, just maybe it is a good idea to at least try.
Cheers!
!BEER
Ahahah love it! I noticed the same problem with ChatGPT, hence why I usually try to avoid it... unless I'm so clueless that I have no idea what to do 😅 and this happens too often lately...
I saw you inserted a lot of error-checking in your script, so, if you don't mind, I'll take some inspiration from yours :)
There's plenty of room for improvements in my script and I only have to find the will to start working on it again 🤣
View or trade
BEER
.Hey @arc7icwolf, here is a little bit of
BEER
from @gamer00 for you. Enjoy it!Do you want to win SOME BEER together with your friends and draw the
BEERKING
.