soranoo / TradingView-Free-Webhook-Alerts

Free TradingView webhook alert for basic plan users.
GNU General Public License v3.0
178 stars 66 forks source link

global variables not working on Pipedream python ? #40

Closed OmarSaidIbrahim closed 1 year ago

OmarSaidIbrahim commented 1 year ago

Hi there, I tried your cloud version pipedream.py code but the global variable won't update on the next email received. Any suggestion ? I am trying to catch the time of the last message received and compare with the new ones.

soranoo commented 1 year ago

May I see your code?

OmarSaidIbrahim commented 1 year ago
# =====================================
# CODE
# =====================================

flag = True
last_message = None

url_regex = "https?://([A-Za-z_0-9.-]+).*"

...

def handler(pd: "pipedream"):   
    # extract data from previous steps
    global flag
    global last_message

    content = pd.steps["trigger"]["event"]["body"]["text"]
    from_email = pd.steps["trigger"]["event"]["headers"]["from"]["value"][0]["address"]
    now = datetime.utcnow()
    current_time = now.strftime("%H:%M")
    today_0800pm_UTC = datetime.strptime("20:00", "%H:%M").strftime("%H:%M")
    today_0230pm_UTC = datetime.strptime("14:30", "%H:%M").strftime("%H:%M")
    if last_message != None and has_new_day_started(last_message, now):
        flag = True
    if current_time > today_0230pm_UTC and current_time < today_0800pm_UTC:
        if flag:
            send_webhook(content)
            flag = False
            last_message = now

@soranoo

soranoo commented 1 year ago

Pipedream will stop the script after a certain time, it also means no variables can be saved. If you really want to save something for future use you may check out Data Stores. Notice that the feature is still in beta.

OmarSaidIbrahim commented 1 year ago

Thank you so much, that helped me a lot