0

This is my js function:

async function get_days() {
    var events = await eel.get_events('ofek')();
    var eve = events[0]['event_name'];
    alert(eve);
    
    
    startPoint = new Date(year, month - 1, 1).getDay(); // 0=Sunday
    numberOfDaysInMonth = new Date(year, month, 0).getDate(); // setting the number of days in the current month
    numberOfDaysInPrevMonth = new Date(year, month - 1, 0).getDate(); // setting the number of days in the prev month
    content = "";
    for (j = 1; j <= startPoint; j++) {
        content += "<li class='prev_next'>" + (numberOfDaysInPrevMonth - startPoint + j) + "</li>";
    
    }
    for (i = 1; i <= numberOfDaysInMonth; i++){
        if (i == currentDate.getDate() && month == currentDate.getMonth() + 1 && year == currentDate.getFullYear()){
            content += "<li onclick='return open_create_event_screen();' class='active'>" + i + "</li>";
        }
        else if (i > currentDate.getDate() && month < currentDate.getMonth() + 1 && year == currentDate.getFullYear()) { // TODO
            content += "<li onclick='return open_create_event_screen();'>" + i + "</li>";
        }
        else { // if the date has already passed - no ability to create event
            content += "<li>" + i + "</li>";
        }
    }
    
    daysNextMonth = 7 - (new Date(year, month, 0).getDay() + 1);
    for (n = 1; n <= daysNextMonth; n++) {
        content += "<li class='prev_next'>" + n + "</li>";
    }
    
    daysDiv.innerHTML = content;
    document.getElementById("current_month").innerHTML = monthNames[month - 1];
    document.getElementById("current_year").innerHTML = year;
    }

This is my python function:

@eel.expose
def get_events(username):
    print("get_events")
    name_of_events = client.get_events(username)
    print(name_of_events)
    return name_of_events

The problem is on the first three lines in the function get_days():

var events = await eel.get_events('ofek')();
var eve = events[0]['event_name'];
alert(eve);

It doesn't succeed to get the value from the python function. If I put those three lines in another function, it succeed. But in this function it can't get the returned value. Does someone know why?

ofek tal
  • 21
  • 3
  • where is `eel.get_events` defined in **javascript**? – Bravo May 09 '22 at 09:05
  • The function get_events is definded on python, I'm using eel. – ofek tal May 09 '22 at 09:06
  • right - so `@eel.expose def get_events(username):` creates a function that returns a Promise that resolves to the value you expect? in other words does `get_events` return a Promise? – Bravo May 09 '22 at 09:07
  • "*It doesn't succeed to get the value from the python function.*" what does that mean? Do you get an error? – VLAZ May 09 '22 at 09:09
  • The problem is not in the function get_events. It returns an expected value. – ofek tal May 09 '22 at 09:09
  • Then what exactly is wrong? What do you expect to happen and what happens instead? – VLAZ May 09 '22 at 09:10
  • I don't get an error. this line: var events = await eel.get_events('ofek')(); just 'stucks' and doesn't succeed move on to the next line. – ofek tal May 09 '22 at 09:10
  • I expect the function to alrert the value of 'eve' but it doesn't do it. – ofek tal May 09 '22 at 09:11
  • Then `eel.get_events` never resolves. But I can't see why. I'm not good with Python and Eel, though. With that said, are you *sure* `eel.get_events('ofek')()` is correct and it shouldn't be `eel.get_events('ofek')`? – VLAZ May 09 '22 at 09:12
  • yes, i'm sure if I put those three lines in another function and I alert the value of 'eve' then it works. it means that the python function works. the js function doesn't succeed to do so. I don't know why – ofek tal May 09 '22 at 09:13
  • I can't figure it out. I really need your help, I'll really appreciate if you guys help me. – ofek tal May 09 '22 at 09:20

0 Answers0