It is currently April 27th, 2024, 9:35 pm

How to use api for unmineable pool?

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

Re: How to use api for unmineable pool?

Post by mtchannel »

I have a very interesting request from you. I did a lot of research to solve it myself so as not to ask you, but I couldn't even come close to what I was looking for.
Now the reason for such a search is the stock market etc. Companies have limited free APIs. I thought of something different.
Let me first explain what I want to do.
First of all, I want to convert the "dollar" currency in the circle in the picture below to the "try" currency. Not all coins on the list are available on a single exchange. I found an exchange that has all of these but there is an API limitation. The fee is too high. I thought something like this. I want it to detect the "dollar $" currency you see for the circle in the picture and display it as the "try" currency opposite it. However, I want to do this without using the API. In short, prices are already taken from the stock exchange and displayed. I want to convert the received dollar$ prices to "try" currency without using the API again. If it can be done, my API problem will disappear.

Image

dolar to try converter
https://www.google.com/search?client=opera&q=dolar+kaç+tl&sourceid=opera&ie=UTF-8&oe=UTF-8

Dollar $ detects the currency and then etc. in the dollar to try link I left above. I want to convert currencies from the site to each other and print the result.

What I want may seem very complicated. I hope I was able to explain what I want. If there is something you do not understand, you can ask.
User avatar
Yincognito
Rainmeter Sage
Posts: 7178
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: How to use api for unmineable pool?

Post by Yincognito »

mtchannel wrote: March 17th, 2024, 11:41 pm I have a very interesting request from you. I did a lot of research to solve it myself so as not to ask you, but I couldn't even come close to what I was looking for.
Now the reason for such a search is the stock market etc. Companies have limited free APIs. I thought of something different.
Let me first explain what I want to do.
First of all, I want to convert the "dollar" currency in the circle in the picture below to the "try" currency. Not all coins on the list are available on a single exchange. I found an exchange that has all of these but there is an API limitation. The fee is too high. I thought something like this. I want it to detect the "dollar $" currency you see for the circle in the picture and display it as the "try" currency opposite it. However, I want to do this without using the API. In short, prices are already taken from the stock exchange and displayed. I want to convert the received dollar$ prices to "try" currency without using the API again. If it can be done, my API problem will disappear.

Image

dolar to try converter
https://www.google.com/search?client=opera&q=dolar+kaç+tl&sourceid=opera&ie=UTF-8&oe=UTF-8

Dollar $ detects the currency and then etc. in the dollar to try link I left above. I want to convert currencies from the site to each other and print the result.

What I want may seem very complicated. I hope I was able to explain what I want. If there is something you do not understand, you can ask.
In terms of detecting the currency symbols in strings or doing the math, this is possible. However, you'd still need to know all the exchange rates between currencies, and unless you have a professional / international banker as a friend or you find a site providing all these for free, you'd still have to go online and check them out. Only around 50 currencies have a fixed exchange rate to some other currency, so for the rest you'll need to find either a single or multiple web source(s) providing the rates - even if those rates are based on a single major currency (like the dollar), it would be enough, since you could do the rest of the basic math needed to convert between any of them. Googling for "all currencies" does provide complete lists and limited conversion possibilities, but for more I guess you'll need to search further. Alternatively to grabbing such data from a single source / API, I guess you could just write 150+ WebParser measures querying different sources (presumably free), each for some specific currency, at the same time, then aggregate everything in the skin. Obviously, if you're only interested in the major currencies, I think you can find free sources / APIs - see for example Mordasius' financial skin here, which uses cnbc.com as a source:
https://forum.rainmeter.net/viewtopic.php?t=36931
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
mtchannel
Posts: 24
Joined: October 21st, 2021, 11:08 pm

Re: How to use api for unmineable pool?

Post by mtchannel »

I just found a very nice site. Gives 10000 credits per day for API. It resets every 24 hours. Not a problem for me. quite enough.
site :

Code: Select all

https://www.livecoinwatch.com/tools/api
I managed to get it working when I checked the api documentation.
I quickly became a member and created an API key. then from the api documentation;

Code: Select all

https://livecoinwatch.github.io/lcw-api-docs/#coinssingle
I ran this code.

The "rate" part in the output is the part that works for me.

example python content;

Code: Select all

import requests
import json

url = "https://api.livecoinwatch.com/coins/single"

payload = json.dumps({
  "currency": "TRY",
  "code": "BTC",
  "meta": True
})
headers = {
  'content-type': 'application/json',
  'x-api-key': '90290ad6-4e32-4117-a2ac-9c16cdca060e'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
After pasting this code into the text document and saving it as "test.py", I run cmd as administrator and type "test.py" and the screen below works.
Image

I tried to adapt "rainmeter" with the method you taught. I'm making a mistake somewhere but I don't understand. Let me share with you the code I adapted. show me my mistake.

Code: Select all

[Rainmeter]
Update=100
Author=-MTCHANNEL-
BackgroundMode=2
SolidColor=0,0,0,1
MiddleMouseUpAction=[!Refresh]
RightMouseUpAction=[!SkinCustomMenu]
DynamicWindowSize=1
AccurateText=1

---10000credit APi---
[10000credit]
Measure=Plugin
Plugin=RunCommand
Program=python
Parameter=test.py
State=Hide
OutputType=ANSI
RegExpSubstitute=1
Substitute="(?siU)^(?:.*'rate':(.*)[,}].*|.*)$":"\1","^\\\d+$":"","(?:^\s+|\s+$)":"","(?:^'|'$)":""    <<<< (I tried this part in different variations. I 100% think I'm getting an error in this part.)
---10000credit APi---

---APi CONNECT---
[10000creditRate]
Meter=String
UpdateDivider=60
OnUpdateAction=[!CommandMeasure 10000credit "Run"]
---APi CONNECT---

---10000creditText---
[10000creditText]
Meter=String
X=230
Y=201
FontFace=Consolas
FontColor=255,255,255,255
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,50
FontSize=15
AntiAlias=1
MeasureName=10000credit
Text= : %1 TRY
DynamicVariables=1
---10000creditText---
User avatar
Yincognito
Rainmeter Sage
Posts: 7178
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: How to use api for unmineable pool?

Post by Yincognito »

mtchannel wrote: March 18th, 2024, 10:44 am I just found a very nice site. Gives 10000 credits per day for API. It resets every 24 hours. Not a problem for me. quite enough.
site :

Code: Select all

https://www.livecoinwatch.com/tools/api
I managed to get it working when I checked the api documentation.
I quickly became a member and created an API key. then from the api documentation;

Code: Select all

https://livecoinwatch.github.io/lcw-api-docs/#coinssingle
I ran this code.

The "rate" part in the output is the part that works for me.

example python content;

Code: Select all

import requests
import json

url = "https://api.livecoinwatch.com/coins/single"

payload = json.dumps({
  "currency": "TRY",
  "code": "BTC",
  "meta": True
})
headers = {
  'content-type': 'application/json',
  'x-api-key': '90290ad6-4e32-4117-a2ac-9c16cdca060e'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
After pasting this code into the text document and saving it as "test.py", I run cmd as administrator and type "test.py" and the screen below works.
Image

I tried to adapt "rainmeter" with the method you taught. I'm making a mistake somewhere but I don't understand. Let me share with you the code I adapted. show me my mistake.

Code: Select all

[Rainmeter]
Update=100
Author=-MTCHANNEL-
BackgroundMode=2
SolidColor=0,0,0,1
MiddleMouseUpAction=[!Refresh]
RightMouseUpAction=[!SkinCustomMenu]
DynamicWindowSize=1
AccurateText=1

---10000credit APi---
[10000credit]
Measure=Plugin
Plugin=RunCommand
Program=python
Parameter=test.py
State=Hide
OutputType=ANSI
RegExpSubstitute=1
Substitute="(?siU)^(?:.*'rate':(.*)[,}].*|.*)$":"\1","^\\\d+$":"","(?:^\s+|\s+$)":"","(?:^'|'$)":""    <<<< (I tried this part in different variations. I 100% think I'm getting an error in this part.)
---10000credit APi---

---APi CONNECT---
[10000creditRate]
Meter=String
UpdateDivider=60
OnUpdateAction=[!CommandMeasure 10000credit "Run"]
---APi CONNECT---

---10000creditText---
[10000creditText]
Meter=String
X=230
Y=201
FontFace=Consolas
FontColor=255,255,255,255
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,50
FontSize=15
AntiAlias=1
MeasureName=10000credit
Text= : %1 TRY
DynamicVariables=1
---10000creditText---
I don't know why you insist in using a python script to access what should be easily available to a WebParser measure assuming a correct query address (the only reason I could think of for this is WebParser not being able to use session-based authentication or logins, though this should be possible if the API allows passing your key or whatever as a parameter in the URL query string), but anyway...

The problem, as far as I could tell, is the fact that you still use ' as field and value delimiter in your regex patterns. I already explained this above, you should use " as field and value delimiters (just like in the response from the site), and use ' as the substitution parts delimiters when such parts include " quotes (or viceversa, if the site uses ' as field and value delimiters). In other words, your pattern contents should replicate the syntax in your response, so they can match what's being there.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
mtchannel
Posts: 24
Joined: October 21st, 2021, 11:08 pm

Re: How to use api for unmineable pool?

Post by mtchannel »

I changed all my APIs to Python. That's why I insist :)

Image[/url]

It works in cmd screen. but when I run "rainmeter" I get the unicode error in the image. I tried different unicodes. I think it's a font style error. I'm trying different alternatives now.
User avatar
Yincognito
Rainmeter Sage
Posts: 7178
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: How to use api for unmineable pool?

Post by Yincognito »

mtchannel wrote: March 18th, 2024, 12:22 pm I changed all my APIs to Python. That's why I insist :)

Image[/url]

It works in cmd screen. but when I run "rainmeter" I get the unicode error in the image. I tried different unicodes. I think it's a font style error. I'm trying different alternatives now.
Oh, I see. Well, since I probably won't be able to test the API, by the looks of it this seems like a python script error. If the STDOUT output text shows up properly (in the log or by displaying it in the skin) after running the RunCommand, then there's no need to change the value of the OutputType option (plus, its value doesn't influence the actual output of the script anyway, only what you get to see as the measure output):
https://docs.rainmeter.net/manual/plugins/runcommand/

I'd say that maybe some parameter / function in python can help, or, you can try using %ComSpec% /U /C as the value of the Program option and python test.py as the value of the Parameter option to see if it solves anything.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Yincognito
Rainmeter Sage
Posts: 7178
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: How to use api for unmineable pool?

Post by Yincognito »

mtchannel wrote: March 18th, 2024, 12:22 pmIt works in cmd screen. but when I run "rainmeter" I get the unicode error in the image. I tried different unicodes. I think it's a font style error. I'm trying different alternatives now.
Alright, I've been able to test your code and try out different fixes, but I'm not familiar enough with python yet to make it work. What I can say for sure is that it's definitely related to this (so, it's a python issue, not a Rainmeter one):
https://stackoverflow.com/questions/10569438/how-to-print-unicode-character-in-python
Yes, I tried various variants from that page and others, and although the error message changed, it didn't print the expected result. Maybe you'll have better luck with this - if you do, post the solution here as well, maybe it will help others that might have the same problem in the future.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Yincognito
Rainmeter Sage
Posts: 7178
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: How to use api for unmineable pool?

Post by Yincognito »

mtchannel wrote: March 18th, 2024, 12:22 pmIt works in cmd screen. but when I run "rainmeter" I get the unicode error in the image. I tried different unicodes. I think it's a font style error. I'm trying different alternatives now.
Found a solution (sort of)!

test.py:

Code: Select all

import codecs
import sys
import requests
import json

url = "https://api.livecoinwatch.com/coins/single"

payload = json.dumps({
  "currency": "TRY",
  "code": "BTC",
  "meta": True
})
headers = {
  'content-type': 'application/json',
  'x-api-key': '90290ad6-4e32-4117-a2ac-9c16cdca060e'
}

response = requests.request("POST", url, headers=headers, data=payload)
print(response.text.encode('utf-8'))
skin.ini:

Code: Select all

[Rainmeter]
Update=1000
Author=-MTCHANNEL-
BackgroundMode=2
SolidColor=0,0,0,1
MiddleMouseUpAction=[!Refresh]
;RightMouseUpAction=[!SkinCustomMenu]
DynamicWindowSize=1
AccurateText=1

---10000credit APi---
[10000credit]
Measure=Plugin
Plugin=RunCommand
Program=python
Parameter=test.py
State=Hide
OutputType=UTF8
RegExpSubstitute=1
Substitute='(?siU)^(?:.*"rate":(.*)[,}].*|.*)$':"\1","^\\\d+$":"","(?:^\s+|\s+$)":"",'(?:^"|"$)':""
---10000credit APi---

---APi CONNECT---
[10000creditRate]
Meter=String
UpdateDivider=60
---APi CONNECT---

---10000creditText---
[10000creditText]
Meter=String
X=230
Y=201
FontFace=Consolas
FontColor=255,255,255,255
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,50
FontSize=15
AntiAlias=1
MeasureName=10000credit
Text= : %1 TRY
LeftMouseUpAction=[!CommandMeasure 10000credit "Run"]
DynamicVariables=1
---10000creditText---
The output still has a b' at the start and the Unicode symbols are in the \x... form, but at least the error is gone and the \x... can easily be converted to what they mean using Substitutes if the entire output is desired, see here:
https://docs.rainmeter.net/manual/variables/character-variables/
Or, you could perfect the method yourself in python, so that such substitutions in Rainmeter wouldn't be required and funky characters would be printed properly to STDOUT from the start.
try.jpg
Note: I saw that you used Update=100 and UpdateDivider=60 in your original code. This means python and the request is ran every 100 * 60 = 6000 milliseconds = 6 seconds. Not sure if it's reasonable from the site's point of view, but well, you'll be the one to lose if they think otherwise - I did my part and explained why... :confused:
You do not have the required permissions to view the files attached to this post.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
mtchannel
Posts: 24
Joined: October 21st, 2021, 11:08 pm

Re: How to use api for unmineable pool?

Post by mtchannel »

I will test the codes you gave. There is a slight improvement for me. Check this out if you want.

Code: Select all

test.py;

import requests
import json

url = "https://api.livecoinwatch.com/coins/single"

payload = json.dumps({
  "currency": "TRY",
  "code": "BTC",
  "meta": True
})
headers = {
  'content-type': 'application/json',
  'x-api-key': '90290ad6-4e32-4117-a2ac-9c16cdca060e'
}

response = requests.request("POST", url, headers=headers, data=payload)
response.encoding = response.apparent_encoding
print(response.text)
note: "Update=100 and UpdateDivider=60" Yes, I did these like this. because if you do this every 60 seconds, it will be defeated. If I do "Update=1000 and UpdateDivider=60", it is refreshed every 150 seconds. Frankly, I didn't understand either.
User avatar
Yincognito
Rainmeter Sage
Posts: 7178
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: How to use api for unmineable pool?

Post by Yincognito »

mtchannel wrote: March 18th, 2024, 2:53 pmCheck this out if you want.
It gives me the same error as in your original code. So, for me, what I posted the last time works.
mtchannel wrote: March 18th, 2024, 2:53 pmnote: "Update=100 and UpdateDivider=60" Yes, I did these like this. because if you do this every 60 seconds, it will be defeated. If I do "Update=1000 and UpdateDivider=60", it is refreshed every 150 seconds. Frankly, I didn't understand either.
I believe you, but I seriously doubt it updated every 150 seconds if you properly told it to update every 60 seconds. Proof:

Code: Select all

import codecs
import sys
import requests
import json

url = "https://api.livecoinwatch.com/coins/single"

payload = json.dumps({
  "currency": "TRY",
  "code": "BTC",
  "meta": True
})
headers = {
  'content-type': 'application/json',
  'x-api-key': '90290ad6-4e32-4117-a2ac-9c16cdca060e'
}

response = requests.request("POST", url, headers=headers, data=payload)
print(response.text.encode('utf-8'))

Code: Select all

[Rainmeter]
Update=1000
Author=-MTCHANNEL-
BackgroundMode=2
SolidColor=0,0,0,1
MiddleMouseUpAction=[!Refresh]
;RightMouseUpAction=[!SkinCustomMenu]
DynamicWindowSize=1
AccurateText=1

---10000credit APi---
[10000credit]
Measure=Plugin
Plugin=RunCommand
Program=python
Parameter=test.py
State=Hide
OutputType=UTF8
;RegExpSubstitute=1
;Substitute='(?siU)^(?:.*"rate":(.*)[,}].*|.*)$':"\1","^\\\d+$":"","(?:^\s+|\s+$)":"",'(?:^"|"$)':""
---10000credit APi---

---APi CONNECT---
[10000creditRate]
Meter=String
UpdateDivider=60
OnUpdateAction=[!Log "Running the command"][!CommandMeasure 10000credit "Run"]
---APi CONNECT---

---10000creditText---
[10000creditText]
Meter=String
X=230
Y=201
W=600
FontFace=Consolas
FontColor=255,255,255,255
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,50
FontSize=15
AntiAlias=1
ClipString=2
MeasureName=10000credit
Text= : %1 TRY
DynamicVariables=1
---10000creditText---
Updates.jpg
For testing purposes, I intentionally commented out the subtitutions, added a ClipString option to the meter, and also added a !Log bang to print out when the command is ran to the Rainmeter log seen in the screenshot. As you can see from the timestamps in the screenshot, python is ran every minute, something you can easily confirm by looking at the "hour" and "day" values at the end of the response displayed by the skin (which is why I temporarily commented out the substitutions, so I can see that).
You do not have the required permissions to view the files attached to this post.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth