It is currently May 19th, 2024, 7:31 pm

If anyone is bored, I'll wait :) I'm waiting for professionals

Get help with creating, editing & fixing problems with skins
User avatar
mtchannel
Posts: 31
Joined: October 21st, 2021, 11:08 pm

If anyone is bored, I'll wait :) I'm waiting for professionals

Post by mtchannel »

Hello. First of all, our subject is actually very simple, but there are some factors that make it difficult. I came up with half-baked solutions of my own, but maybe I was holding my left ear with my right hand. That's why I can say I couldn't complete the project.
First of all, the most important factor that makes it difficult is that there is no "API" for the web page.
So what is the summary of our topic?
01-) There is a mining site called ravenminer.com.
02-) However, since there is no API support on this site, I cannot make "balance" type requests.
03-) The only thing I can do is follow through the web browser. I prefer to use "api" because there is too much unnecessary information in my opinion.

First let me present to you what I did. Afterwards, I can continue with what I did or listen if you have alternative options.
First, I would like to share with you what I have done, item by item.

01-) "Google Chrome" must be installed on the PC.
02-) "Python" must be installed on the PC.
03-) After installing "google chrome" and "python", we need to install the "pip install import PyPDF2" module on the cmd screen as an administrator.
04-) Now everything is ready. First of all, we open a folder named "ravenminer" in the main directory of the local disk (c) so that our work is easier and all files are easy to find.
05-) We create 1 bat file in the folder. We write the name of the .bat file "webtopdf". We paste the following codes into it.
Codes to be written into .bat; (Adjust its location accordingly wherever Google Chrome is installed. Since I am using a portable, I had to specify a location. Maybe you don't need it either.)

Code: Select all

c:
CD/
cd GoogleChromePortable
cd App
cd Chrome-bin
chrome.exe --headless --disable-gpu --print-to-pdf="C:\ravenminer\output.pdf" --virtual-time-budget=10000 "https://www.ravenminer.com/zephyr/wallet /ZEPHYR2u8Zg9uwdHHU5oQRG2ZDniADy71M1m7VwA1T9yHHEirSAJffBGx4QhbsurRX9jK6FgWxD7DHwGmxAQHYqZ7ABLifBAiEM1o"
06-) Now we are done with the .bat file. Now it's time for the python code.
07-) Now we create an empty .py file inside the "ravenminer" folder. We name the .py file ravenminer.py. We copy the following codes into it.
python;

Code: Select all

import PyPDF2

with open('output.pdf', 'rb') as pdf_file:
    pdf_reader = PyPDF2.PdfReader(pdf_file)
    
    pdf_text = "ZEPH"
    for page_num in range(len(pdf_reader.pages)):
        page = pdf_reader.pages[page_num]
        text = page.extract_text()
        if "ZEPH" in text.split():
            pdf_text += text

print(pdf_text)
08-) Now first we double click on "webtopdf.bat". After clicking it will put a file named "output.pdf" in the "C:\ravenminer" folder. We have now saved the web page as a pdf.
09-) Now it's time to run the Python code. We open the cmd screen as administrator. We write python.py. If everything is correct, the following image should appear in front of us.
sample image;
python sample image;
Image[/url]

The place I want to see on rainmeter.
Image[/url]

10-) So what are the things I've done so far?
1-) We first converted the web page to pdf.
2-) We entered the text in the pdf that we wanted to see into Python. (This is where the problem starts. I just wanted clear pending, but no matter what I write, all the texts come)
3-) I am trying to retrieve the data that says "cleared pending" in the texts we shot with Python using webparser in Rainmeter, but I failed.

As you can see, I went on a long journey because there was no "api". If anyone wants to help or is bored about this issue, I welcome everyone to this thread :)

rainmeter example code;

Code: Select all

[ravenminer]
Measure=Plugin
Plugin=RunCommand
Program=python
State=Hide
Parameter=ravenminer.py
OutputType=UTF8
RegExpSubstitute=1
Substitute=(((There is nothing I haven't tried :)))

[ravenminerBalance]
Meter=String
UpdateDivider=60
OnUpdateAction=[!CommandMeasure ravenminer "Run"]

[ravenminerBalanceText]
Meter=String
X=230
Y=912
FontFace=Consolas
FontColor=255,255,255,255
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,50
FontSize=15
AntiAlias=1
MeasureName=ravenminer
Text= :%1 ZEPHYR
DynamicVariables=1
Last edited by balala on May 5th, 2024, 6:09 pm, edited 1 time in total.
Reason: Please use <code> tags whenever are you posting codes. It's the </> button.
User avatar
Yincognito
Rainmeter Sage
Posts: 7290
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: If anyone is bored, I'll wait :) I'm waiting for professionals

Post by Yincognito »

mtchannel wrote: May 5th, 2024, 5:41 pm(This is where the problem starts. I just wanted clear pending, but no matter what I write, all the texts come)
3-) I am trying to retrieve the data that says "cleared pending" in the texts we shot with Python using webparser in Rainmeter, but I failed.
Didn't you mean "Cleared Balance" instead of "Cleared Pending"? Cause that's what both your screenshots show... :???:

To save us from going on the same route pointlessly, did you get something from your [ravenminer] measure (in the log or otherwise)? You seem to imply that you got the entire text. If so, how exactly does that text look like? As in your 1st screenshot, or can it be different? Posting how it looks between [ code ] tags (the </> or the 5th button above your message box) would help more than a screenshot in that regard, if by any chance this is only about a (RegExp-) Substitute to extract only the "Cleared Balance..." to the end part. Also, would help to know what (visible or invisible) characters are before "Cleared Balance".
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
mtchannel
Posts: 31
Joined: October 21st, 2021, 11:08 pm

Re: If anyone is bored, I'll wait :) I'm waiting for professionals

Post by mtchannel »

Screenshot from .pdf file taken with; webtopdf.bat.
Image

python screenshot output; ravenminer.py
Image

I meant "Cleared Balance". There was a word mistake. This can happen from time to time when using Google Translate. Especially in very long texts, control is lost :)
User avatar
mtchannel
Posts: 31
Joined: October 21st, 2021, 11:08 pm

Re: If anyone is bored, I'll wait :) I'm waiting for professionals

Post by mtchannel »

It is a very troublesome event. Maybe there is an easy way, I don't know. What I actually do is, since the web page does not have API support, I first download the entire web page as a pdf. Then I try to pull the balance to rainmeter using webparser with python.
User avatar
Yincognito
Rainmeter Sage
Posts: 7290
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: If anyone is bored, I'll wait :) I'm waiting for professionals

Post by Yincognito »

mtchannel wrote: May 5th, 2024, 10:03 pm It is a very troublesome event. Maybe there is an easy way, I don't know. What I actually do is, since the web page does not have API support, I first download the entire web page as a pdf. Then I try to pull the balance to rainmeter using webparser with python.
Sorry, but you still didn't:
- tell us if you did get something from your [ravenminer] measure? (you only screenshot the python result, didn't say anything about the measure outcome)
- post how the above looks between [ code ] tags, i.e. as text, which is more helpful than a screenshot (that would reveal all characters there as well)
Since you didn't, the help is also incomplete - you can try something like:

Code: Select all

RegExpSubstitute=1
Substitute="(?siU)^.*(Cleared Balance.*)$":"\1","^\\\d+$":""
to get everything from Cleared Balance (inclusive) to the end, or

Code: Select all

RegExpSubstitute=1
Substitute="(?siU)^.*Cleared Balance\R(.*)\R.*$":"\1","^\\\d+$":""
to get the "0.0000050 ZEPH" part only.

In case you wonder, \R means a newline sequence (either \r\n or just \n, with \r being the carriage return character, and the \n being the line feed one), ^ means the beggining of the string, $ means the end of the string, ( and ) enclose the capture, \1 references the first capture, \d means digit.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
mtchannel
Posts: 31
Joined: October 21st, 2021, 11:08 pm

Re: If anyone is bored, I'll wait :) I'm waiting for professionals

Post by mtchannel »

Unfortunately, the mouse left click is faulty. While copying to translate your message, I copied it incompletely. I've just realized. Excuse me please. Actually, I mentioned it in the first message. Because there is nothing left that I haven't tried. Unfortunately, there is a word error in the sentence again. That's why the wrong translation was made. I am sad. ("Edit=(((There is nothing I haven't tried :)))") .. I couldn't share the result because I couldn't get any output from rainmeter.


python output;
ZEPHRM
₿ 0.00012311  -3,2% | $ 7,89 -2,0%
Earnings History Estimated Earnings
Wallet Hashrate Wallet BalanceSearch wallet address
Dashboard Blocks Wallet How-T oFAQ Mining-Software
Miner statistics for
ZEPHYR2u8Zg9uw dHHU5oQR G2ZDniADy71M1m7VwA1T9yHHEirSA JffBGx4QhbsurRX9
jK6FgWxD7DHwGmxAQHY qZ7ABLifBAiEM1o
Hashrate
0 H/sWorkers
0 | 1Payout Coin
ZEPHCleared Balance
0.0000050 ZEPH
Pending 0.0 ZEPH ₿0.0 $0.0
Cleared 0.0000050 ZEPH ₿0,00000000 $0.000040
T otal 0.0000050 ZEPH ₿0,00000000 $0.000040Balance
1 day 0.0000050 ZEPH ₿0,00000000 $0.000040
7 days 0.0000050 ZEPH ₿0,00000000 $0.000040
14 days 0.0000050 ZEPH ₿0,00000000 $0.000040
30 days 0.0000050 ZEPH ₿0,00000000 $0.0000406.05.2024 07:52 Zephyr Wallet ZEPHY.... EM1o - RavenM ner
https://www.ravenm ner.com/zephyr/wallet/ZEPHYR2u8Zg9uwdHHU5oQRG2ZDn ADy71M1m7VwA1T9yHHE rSAJffBGx4QhbsurRX9jK6FgWxD7DH… 1/2
User avatar
mtchannel
Posts: 31
Joined: October 21st, 2021, 11:08 pm

Re: If anyone is bored, I'll wait :) I'm waiting for professionals

Post by mtchannel »

test-1;
RegExpSubstitute=1
Substitute="(?siU)^.*(Cleared Balance.*)$":"\1","^\\\d+$":""

test-2;
RegExpSubstitute=1
Substitute="(?siU)^.*Cleared Balance\R(.*)\R.*$":"\1","^\\\d+$":""
Image

I tried both alternatives above. It gives the error in the picture.
We got an error like this before, do you remember? We fixed it by setting "OutputType=ANSI". but this time it didn't get better. I changed ravenminer.py to ANSI. It didn't work again. I brought it back to its original state. I converted the .ini and .py back to UTF8 format.
User avatar
Yincognito
Rainmeter Sage
Posts: 7290
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: If anyone is bored, I'll wait :) I'm waiting for professionals

Post by Yincognito »

mtchannel wrote: May 6th, 2024, 5:08 am I tried both alternatives above. It gives the error in the picture.
We got an error like this before, do you remember? We fixed it by setting "OutputType=ANSI". but this time it didn't get better. I changed ravenminer.py to ANSI. It didn't work again. I brought it back to its original state. I converted the .ini and .py back to UTF8 format.
That's the whole reason I asked you what the output from the MEASURE is, and NOT FROM PYTHON. I - or anyone here, for that matter - can't debug your Python script or its result (well, we could, but we're on a Rainmeter forum, after all), that's your job. However, as long as you get a proper result in the measure from the Rainmeter skin, the Substitute will definitely work. By the way, I'm not so sure that changing the .py or .ini file encoding matters that much in this case, it's mainly the script and measure result that has to be configured properly in terms of encoding to get an intelligible result on one hand, and match the encodings between the script output and the measure one on the other hand.

So basically, once you get an output from the [ravenminer] measure that matches the python script output you just posted as text above, then we can talk about the Substitute part. I alluded to that earlier in our conversations, there should be some functions in Python to encode the result as desired, but since we're not exactly experts in Python here, it's probably the wrong place to ask about that (a Python forum or StackOverflow might be more suited for that, AS LONG as you describe your issue correctly and you know exactly what encoding you want so that it can be read by the Rainmeter measure).
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
mtchannel
Posts: 31
Joined: October 21st, 2021, 11:08 pm

Re: If anyone is bored, I'll wait :) I'm waiting for professionals

Post by mtchannel »

With a small correction in Python, I can now get "cleared balance". Not having an API was such a hassle.

Code: Select all

import PyPDF2

with open('output.pdf', 'rb') as pdf_file:
    pdf_reader = PyPDF2.PdfReader(pdf_file)
    
    pdf_text = u"ZEPH"
    for page_num in range(len(pdf_reader.pages)):
        page = pdf_reader.pages[page_num]
        text = page.extract_text()
        if "ZEPH" in text.split():
            pdf_text += text

encoded_pdf_text = pdf_text.encode('utf-8')

print(encoded_pdf_text)
It will be completed with a minor adjustment.
Image
User avatar
mtchannel
Posts: 31
Joined: October 21st, 2021, 11:08 pm

Re: If anyone is bored, I'll wait :) I'm waiting for professionals

Post by mtchannel »

has been completely resolved.
Image

By combining the commands in .bat with python I was able to create a single ravenminer.py file. Let me share the codes. Maybe someone will need it.

python;

Code: Select all

import PyPDF2
import re
import subprocess

pdf_path = "C:/Program Files/Rainmeter/Rainmeter Skins/Skins/KISAYOLLAR/05coinhavuzkazanclari/python/ravenminer/output.pdf"

web_page_url = "https://www.ravenminer.com/zephyr/wallet/walletaddress"

chrome_path = "C:\\GoogleChromePortable\\App\\Chrome-bin\\chrome.exe"
command = [
    chrome_path,
    "--headless",
    "--disable-gpu",
    f"--print-to-pdf={pdf_path}",
    "--virtual-time-budget=500",
    web_page_url
]

subprocess.run(command)

with open(pdf_path, 'rb') as pdf_file:
    pdf_reader = PyPDF2.PdfReader(pdf_file)
    
    cleared_balance_amount = ""
    
    for page_num in range(len(pdf_reader.pages)):
        page = pdf_reader.pages[page_num]
        text = page.extract_text()

        match = re.search(r'Cleared Balance\s+(\d+\.\d+)', text)
        if match:
            cleared_balance_amount = match.group(1)
            break 

print("", cleared_balance_amount, end="")
What does python code do?
01-) Opens Google Chrome
02-) loads the specified page (waits 5 seconds for the page to load and hides it in the background)
03-) Saves as pdf to the specified directory
04-) searches for "Cleared Balance" in the saved pdf file and displays the relevant figure.

All that remains is to show "Cleared Balance" with rainmeter. I accomplished these with the code below.
rainmeter code;

Code: Select all

[Ravenminer]
Measure=Plugin
Plugin=RunCommand
Program=python
State=Hide
Parameter=python\ravenminer\ravenminer.py
OutputType=ANSI
RegExpSubstitute=1
Substitute="":"  (Since I have already obtained the "Cleared Balance" balance with Python, I do not need to search again. The balance appears. In this case, rainmeter will only show the data coming from Python)

[Ravenminer-ZephyrOdenecekBakiye]
Meter=String
UpdateDivider=60
OnUpdateAction=[!CommandMeasure Ravenminer "Run"]

[Ravenminer-ZephyrOdenecekBakiyeText]
Meter=String
X=230
Y=645
FontFace=Consolas
FontColor=255,255,255,255
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,50
FontSize=15
AntiAlias=1
MeasureName=Ravenminer
Text= :%1 ZEPHYR
DynamicVariables=1
Yes, we solved another problem together. "Yincognito" helped me a lot. THANK YOU