Channel edit topic in a loop, strange acting - python-requests

today i'm struggling to edit a discord channel topic in a loop. By that I mean that it sometimes works sometimes don't, and it gets really strange. The code :
#tasks.loop(seconds=5)
async def prixcrypto():
channel = client.get_channel(776053500059975690)
databtc = requests.get('https://api.binance.com/api/v1/ticker/24hr?symbol=BTCUSDT') #Get bitcoin/usdt actual price and information over a 24h period
jdata = databtc.json()
datavet = requests.get('https://api.binance.com/api/v1/ticker/24hr?symbol=VETUSDT').json() #same for vet/usdt
#Here I print the data I want (symbol of crypto, price, priceChangePercent(24h,%), priceChange(24h,$)
print(f'{datavet["symbol"]} : {format(float(datavet["bidPrice"]),".6f")} / 24H : {datavet["priceChangePercent"]}% / 24H : {format(float(datavet["priceChange"]), ".2f")}$')
print(f'{jdata["symbol"]} : {format(float(jdata["bidPrice"]),".2f")} / 24H : {jdata["priceChangePercent"]}% / 24H : {format(float(jdata["priceChange"]), ".2f")}$')
#Here I send to the channel the string with values
phrase = (f'{jdata["symbol"]} : {format(float(jdata["bidPrice"]),".2f")} / 24H : {jdata["priceChangePercent"]}% / 24H : {format(float(jdata["priceChange"]), ".2f")}$ || {datavet["symbol"]} : {format(float(datavet["bidPrice"]),".6f")} / 24H : {datavet["priceChangePercent"]}% / 24H : {format(float(datavet["priceChange"]), ".6f")}$')
await channel.edit(topic=phrase)
#prixcrypto.before_loop #Initiate the loop when client is ready
async def before_prixcrypto():
await client.wait_until_ready()
prixcrypto.start()
The result is something like this :
Cmd :
VETUSDT : 0.017466 / 24H : 8.205% / 24H : 0.00$
BTCUSDT : 19360.00 / 24H : 2.869% / 24H : 540.00$
Discord Topic :
BTCUSDT : 19360.00 / 24H : 2.869% / 24H : 540.00$ || VETUSDT : 0.017466 / 24H : 8.205% / 24H : 0.00$
What I want to happen : I start the program, and then it prints the results, then it should change the topic and it loops every 5 seconds.
What it does : I start the program, it prints the results on cmd, then it doesn't change the topic, and sometime later it will get back into the function, print the results, change the topic, start again 5 seconds later, print the results, and won't change topic, and it will do that again sometime later. So it's really strange.
It's very strange, and from what I "found", because I'm not sure, it bugs at the "await channel.edit()" line.
I tried to change loop time but it doesn't seem to change anything, I verified it's not a problem with binance API requests limit, I searched on google and found nothing interesting so I don't know.
Your help is welcome, thanks for reading me.
Just to say I started programming 3 months ago and didn't really learn to code in python, i'm just finding what I need to make my ideas real and then do what I need, at my university we learn C. I'm french.

The ratelimits for editing a channel is 2 requests per 10 minutes, you're basically hitting them if you're editing a channel every 5 seconds.

Related

How to check if the device's time is between two times in Flutter from Firebase/Firestore?

In the Firestore project, I have documents in a collection containing data for shops, having fields like shopName, shopAddress, startTime(eg. 10 AM) and closeTime(eg. 10 PM) . (all strings for now)
When the user is browsing the app, i have retrieved the data from Firestore of the shops displayed in the app, now i wanna show that the shop is closed when the device's time is not between the startTime and closeTime of the shop. How do i achieve this?
So far I can detect the device's current time using dart package intl using this code:
print("${DateFormat('j').format(DateTime.now())}");
It gives output as follows:
I/flutter (14877): 6 PM
This is in DateFormat, and the data types stored in Firestore are strings.. I dont know how to compare them.. Do let me know if i have to change the data types in Firestore too.
Thank You
I think if you use 24 Hour Time Format and convert startTime, closeTime and actualTime to int or double ( if the shop close at 20:30/8:30pm), then you can easily compare them with if. On your firebase server string format is perfect.
For example you make a map and iterate it, and check if the actualTime is higher than startTime and lower than closeTime.
I have never tried this code, but i think it is going to work.
Map map = {'1am': 1, '2am': 2, '3am': 3, ... , '11pm': 23};
map.entries.forEach((e) {
if(e.key == actualTime) {
if(e.value >= startTime && e.value < closeTime) {
print('Open');
}
else{
print('Closed');
}
}
});
By the way, I think you should use UTC, because if you change the time-zone on your device, your app is going to show that the shop is closed, but in fact the shop is open, just you are in a different time-zone. You can easily implement this with this code.
var now = DateTime.now().toUtc();
Maybe you can create a hash map like this:
hashMap=['12 AM', '1 AM', '2 AM', ... , '11 PM', '12 AM'];
After that you can get the positions of startTime, closeTime and actualTime, and see if the actualTime is between start and close times positions.
Let me know if you want to give you a code example.

While doing a datafix for around 1k record however I get system violation error after 800 records are processed?

I am processing 1k record however I get system violation error after 800 record. Could someone please suggest how can this error be resolved?
There are designated methods for using OQL, you should take care to
Use a cursor variable
Declare a size that makes sense for your query
Open the cursor (allocates memory)
Close the cursor (disposes memory)
procedure ShowMoviesInCategory(theCategory : tCategory)
var Curs : aOQLCursor
var curMovie : aMovie
Curs = Motor.OpenOQLCursor  
Curs.BatchSize = 50
OQL select * from x in aMovie++ where x.Category = theCategory using Curs  
forEach curMovie in Curs
WriteLn(curMovie)
endFor
Motor.CloseOQLCursor(Curs)
endProc
Please also refer to the eWAM Help under OQL and
wTECH 101 (week1 - day 5 "101A - OQL - Search.pptx"
In Wynsure there is a designated variable for this, please refer to the Wynsure Development Rules.docx

NSString format not working on device but working on simulator

just making a basic game and used the NSUserDefaults to save the high score. while calling the i needed to use a NSString with a Format of "Best Time : %i". I Ran the game on the simulator and it worked perfectly.
However when I went to run it on the device the label that i formatted using the NSString(format "Best Time : %i") did not work nothing appeared in the label?
Here is the code I used for calling the saved Best time:
//The previous games best time
var highscoreDefaults = NSUserDefaults.standardUserDefaults()
if (highscoreDefaults.valueForKey("Highscore") != nil){
theNewTime = highscoreDefaults.valueForKey("Highscore") as! NSInteger!
thehighscore.text = NSString(format: "Best Time : %i" , theNewTime) as String
}
//---------------------
You can use Swift's string interpolation as you don't need any advanced features from the C-format specifier:
thehighscore.text = "Best Time : \(theNewTime)"

Meteor Timed variable resets

I'm making a game with meteor and I want certain variables to reset at the end of everyday.. DO you know how I would go about doing that?
Like at the end of everyday the amount of turns goes back to ten.
I recommend you to use momentjs package for this.
First run.
meteor add momentjs:moment
Now you can do the follow
var day = moment().endOf('day').fromNow(),
day1 = moment().startOf('day').fromNow();
console.log("the days ends in " + day)
console.log("the days starts " + day1)
if(day === "in 0 hours"){
alert("The day is over")
Session.set("dayOver",true)
}
if(day1 === "in 24 hours ago"){
alert("The day is over")
Session.set("dayOver",true)
}
Here is the JSFiddle
NOTE: There should be another way, also this take the client time, never trust on the client time, if you want to take the safe time from the server try the mizzao/meteor-timesync package
Try it
meteor add mizzao:time sync
and you can do things like.
var serverTime = TimeSync.serverTime().
serverTime.format(). //for example

OptaPlanner nurse rostering

Discovered OptaPlanner whilst working on a roster generator for a hospital in Malawi, and it would be a perfect fit for the problem. So some newbie questions:
1) I can't see a way to easily enter holidays (apart from multiple day off requests), can see how to add this but don't wish to reinvent the wheel.
2) I can't see a way to add a constraint giving nurses a day off before and 2 days off after a night shift (there are just two shifts, day and night) any suggestions gratefully received, not sure where to start on this one.
Many thanks
It's a matter of adding or editing score rules in the DRL file. For some of them, you'll need to expand the domain model to include extra information (such as holiday start/end etc) and also adjust the XML dataset to include that information.
1) Add a HolidayRequest domain object and do something like this (warning: pseudo code):
rule "holidayRequest"
when
$holidayRequest : HolidayRequest($employee : employee, $startShiftDate : startShiftDate, $endShiftDate : startShiftDate, $weight : weight)
$assignment : ShiftAssignment(employee == $employee, shiftDate >= $startShiftDate, shiftDate <= $endShiftDate)
then
scoreHolder.addSoftConstraintMatch(kcontext, - $weight); // Maybe you want it hard instead of soft?
end
2) I'd rephrase that as (very very pseudo code)
ShiftAssignment(type = DAY, $date)
ShiftAssignment(type = NIGHT, date = $date + 1)
And also don't have this
ShiftAssignment(type = NIGHT, $date)
ShiftAssignment(type = DAY, date = $date + 1)
or this:
ShiftAssignment(type = NIGHT, $date)
ShiftAssignment(type = DAY, date = $date + 2)

Resources