I have a user who will input the date for the next event. It is saved in the format yyyy-mm-dd hh:mm:ss (eg: 2013-06-09 00:00:00) in a MySQL database. How can I write a cron job that sends a notification to the user 3 days in advance about an upcoming event?
You can achieve this in two steps:
You have to write a PHP script that checks in your database if there
is an event coming up three days from now and if so, which user in your
database created that event. If there's an event, the script sends a
reminder email to the user.
In cron you create a task that runs the above mentioned script once
a day.
Now that you know the steps, please try to figure out the implementation yourself.
Related
I am looking for technology suggestions. Or if this can be done in native google sheets (note the site I am looking to access is behind a username and password).
I have a google sheet that looks like this
birth date
link
data_element_from_website
12/31
https://something.com/3920230
1/31
https://something.com/1920238
lets say on https://something.com/3920230 there is a HTML element 123
Twice a day I want to be able to refresh the data, this could be done by going into the spreadsheet and clicking/doing something.
Can this be done?
What if https://something.com/3920230 is behind a login (authentication). Note: I could be logged in to the website in a different tab... I don't think that would make a difference though...
Assuming you have a script that you would like to run twice a day, you can use Apps Script Time-driven triggers:
A time-driven trigger (also called a clock trigger) is similar to a cron job in Unix. Time-driven triggers let scripts execute at a particular time or on a recurring interval, as frequently as every minute or as infrequently as once per month. (Note that an add-on can use a time-driven trigger once per hour at most.)
If it's just some formulae, you can change the recalculation settings to be either On change, On change and every minute or On change and every hour under the File > Spreadsheet settings menu item and clicking on the Calculation tab.
If you want to get data from public site(no login) you can use ImportXML. You can google a lot about it, for example
https://answerbun.com/personal-finance-money/get-revenue-details-in-google-sheets-using-google-finance/
If the page you want can only be accessed using login, this becomes a rather complicated task, especially using only apps script libraries (not much scraping lib support here)
I designed a rather simple Add-On to enable my local team to more easily automate newsletters and target updates to Slack.
The Add-On works well, aside from two issues:
Schedule a send functionality.
I'm using the ScriptApp's newTrigger() function to allow users to schedule automatic sends.
While it seemed to have worked in original tests, the triggers are now triggering at the wrong time (a trigger that should run daily from 11-12AM has been running at 5PM - Another that should run at 6PM has been running at 12AM - I've checked and the timezones appear to be correct GMT+2 for Paris)
GetActive() returning the wrong sheet
This is a minor problem as I've only noticed it twice, but when running a script with getActive() from the correct sheet, it accidentally ran the script using another spreadsheet.
I remain at your disposal should you need any more information, IDs or the likes.
Thank you for any help and have a fantastic day
So I'm just getting back into scripting with GAS and I'm trying to make a scheduler/reminder system for tracking periodic maintenance that has to be done.
The idea is a form that fills info to a spreadsheet (easily done), and then iterate through the sheet and create events on a dedicated calendar for every 'job', with recurrence set to how often the job needs doing. ie: every 3 months, clean the drains.
I have this part of it working. What I'm wondering is... is it possible to have a script call a function at a specified date and time? Like instead of a calendar event that emails you a reminder about the event on the day of (or whenever), maybe call a function so that I can email them some details about the job (again, pulling from the sheet, which is simple enough) and maybe throw it at Pushbullet API to push to the user's phone/browser. I've played with PB's api, and everything, the ONLY part of this that I don't have working is the scheduled future script firing.
If this isn't possible, would anyone be able to recommend an alternative?
Edit: For clarification, I'd be wanting to set up a one-time execution of a function on say ... June 14th. In terms of recurrence, I can just have it set the next scheduled run during the execution.
If I understood correctly, you need to use the Trigger!
Yes, it’s possible. Use time-driven triggers. For details see https://developers.google.com/apps-script/guides/triggers/installable
We're building a platform that fetches data from the AdWords accounts under our AdWords Manager account and saves the data onto BigQuery to be viewed online via nice charts and tables.
As you all know, Adwords numbers need a few days to stabilize. So, every day at 12am we need to refetch all the data for the past 2 weeks and overwrite the data we already have saved for these 2 weeks (we're basically updating the numbers we have).
Our AdWords manager account has 150+ accounts under it. So, when we run the script that fetches the data for all these accounts for the past 2 weeks, understandably, the script times out because it needs more than 65 minutes to be done with the task.
When we looked online for solutions, the only thing we could find was using the "executeInParallel" function provided by the Adwords Script. This should allow us to run a function on several accounts at the same time. Unfortunately, the "executeInParallel" function cannot be called on more than 50 accounts. Since we have 150+ accounts, we cannot call the "executeInParallel" function on them.
We tried splitting the accounts into groups of 50 and calling the "executeInParallel" function on these groups. However, the "executeInParallel" function cannot be called more than once in a single script. This means that we're not able to use this solution.
The only other solution we can think of is to create a script for each one of the 14 days and have each script would fetch the data of all the accounts for a specific day. So, Script1 would fetch the data for today -1. Script2 would fetch the data for today -2 ... Script14 would fetch the data for today -14.
Does anyone else have another solution that we can use?
I never used the adwords apps script service but I see it works with iterators so in apps script we are used to use that with Drive service. What I would do, based on this example script :
var accountSelector = AdsManagerApp
.accounts()
.withCondition("Impressions > 100")
.forDateRange("LAST_MONTH")
.orderBy("Clicks DESC");
var accountIterator = accountSelector.get();
while (accountIterator.hasNext()) {
var account = accountIterator.next();
}
What you can do :
You create a json object where you will store the account id treated.
You store this json in a script property, you have to use json.stringify in order to save the json as text in theproperty.
You use trigger to restart program before it goes over time limit.
Idea is :
You start the program
you initiate the json by getting the property, if empty create blank json
you initiate account selector
you start the while(), inside you test first before to get data if the account is already treated, i.e. have an entry in the json.
If not you get the data and once done you add an entry in the json
I recommend to do that for 10 account for example and not waiting time overdue
When 10 accounts are treated you go out the while (break;) to push the json in the script property
Last, you create a trigger to rerun the function after 90 seconds.
ScriptApp.newTrigger("myFunction")
.timeBased()
.after(90 * 1000)
.create();
Don't forget to delete triggers before to create a new one
Don't forget when you finish iterator to stop everything and reset property for newt run.
Stéphane
These are Webi, user created reports.
Is it possible to schedule a Webi report based on another input, i.e. expose a time in which a process was finished (this can be obtained via a SQL call, service call, etc). The issue is that if a user schedules a report for 9PM but a process to move data, etc has not completed then that forces the user to keep re-freshing the report hoping that the process has been complete.
Ideally, in the selection UI add to the dropdown for 'when' the option 'Use Process X completion Time' (since it is a daily report). Then starting around 9PM check to see if that 'time" value is populated then refresh (run) the report. Or it could just be a flag that the process has finished.
User's in the webi environment are asking for this, and moving their reprots to BO is not an option. That's why they have the custom webi enviroment.
Thank you.
Not sure what version of Webi you're using but if it's XI3.1 then I would use an Event to trigger the report refresh. You'll have to create the Event in the CMC and then add it to the schedule for the report (Events to wait for:).
The Event can be based on a text file. I've had our ETL process create a text file when our load is complete and then setup a Windows task to create various text files that are used as Events in the CMC to trigger groups of report refreshes.
Also, the report has to be waiting for the Event before it occurs and then once the Event occurs the report refreshes. For example, I have set all the reports that are triggered to start at 1 am and end at 9 am. The Windows Scheduled Task to create the text files mentioned previously does not start until 1:01 am. So the reports starting looking for the text file (which doesn't exist) at 1 am then sees the file at 1:01 am then starts the report refresh.
You must have a Windows Scheduled Task to delete the trigger files before your next desired refresh. In my case, the reports are refreshed daily and the files are deleted at 6 pm.