Access Google Apps Scripts from an external site - javascript

I currently have a website that automates Instagram actions: http://instapromobiz.com. It is almost all javascript based, with some php to post to databases. Users login and an entry is created in a mySQL database, containing their username and how many credits they have (1 credit = 1 action). Then users add tags and press start, then the javascript makes requests via Instagrams API, and ajax+php is used to update their database.
The issue is that when the user leaves the page, or even refreshes it, the script will stop. Otherwise it will run forever.
I have a javascript file that contains all the functions needed to run the script until the user stops it.
My question is, can I use Google Apps Scripts to host this .js file so that when the user leaves the page the script continues to run. I've uploaded the code and published it, but I can't figure out how to access it from an external website.
node.js is out of the question, and I'd rather not convert the whole site to php(I don't know php well) and a cron wont work because of all the javascript.
Any help would be great, thanks!

Apps Script is going to be limited to a 5 minute execution time. You could create time based triggers to contend with that functionality to some extent, but the script will stop 5 minutes after being invoked.
If you still think Apps Script is a good fit, you would just need to deploy your script as a web app, and utilize a doGet(event) function or a doPost(event) function to receive the request from your external application. If you need to return content, there is ContentService to help facilitate that part of the process.
To maintain the different data points for each user, you will need to utilize ProertiesService.getUserProperties(), to store persistent string values for each user.
The other part of Apps Script that may come into play with your Javascript, is that Apps Script uses caja sanitization for javascript (just something to be mindful of, if you run into issues).

If you MUST defeat the execution time problem in google apps script. You can monitor the execution time and at a certain point before time expires invoke the script recursively and pass it the parameter of wherever it left off.

Related

Limit the number of times my code is loaded on a web page based on geo targeting - javascript

I have a problem.
I have a piece of code, that I send to websites to be placed inside the <head></head> right at the very beginning of the header. My code will run and collect some data and pass the result to the rest of the page (ad servers, forms, etc., for example).
My problem is that I need to limit the number of times this code can make calls back to my server and that needs to be based on user location (city, more specifically). I cannot use the ad server, and benefit from its targeting capabilities because I do need to run this code before everything else.
I was thinking if there was any sort of script that would allow me to identify the user location and make the decision to whether or not to call my server, therefore making sure that I am only using my resources when it is actually needed.
I thought about using the html5 geolocation API but it requires user interaction. Then I was thinking about using a service like IpRegistry.co, to:
query for the location and if ;
location=desired location;
then load javascript code;
otherwise do nothing;
I am not sure if this is possible and how to do it. Any help would be greatly appreciated and desired. I am ready to explore opportunities here.
If I didn't stress enough, it needs to happen inside the header, not on the body.
Thanks in advance.
PC

New Developer trying to run task on Django without page reload. Possibly Alpine.js

Long time reader. First time poster. I've been using a Django site in a Windows only house for about 2 years. We're running scripts on Cisco network equipment with Paramiko. These tasks are run on multiple devices at times, and are time consuming (anywhere from 20 seconds to 3 minutes). I want to submit the script for processing and provide user live updates while the script runs. My research says that Javascript can do this with Ajax by not requiring a page reload. I'd want to attempt with Alpine.js due to its perceived simplicity. My background is in simpler static HTML/CSS type sites.
Has anyone tried the Django/Alpine combo at this time? I know Channels/Redis/Celery are popular, but these async requests are onesy twosy affairs, and I feel that a full task queue manager is complete overkill, while not being compatible with Windows for me at this time.
I'm not looking for specific code to fix my problem, more direction on how "best" to handle this issue of the user sitting and waiting on a script.
Alpine.js could work for your purposes. It's designed to play nicely with data fetching APIs and libraries such as the fetch Web API and JavaScript HTTP clients.
It's quite easy to adopt into your workflow since you can just include a HTML script tag and start writing Alpine.js components so it would be a good fit for a Django/other server-rendered type of application where this is one of the few instances where you need a bit of client-side interactivity.
As for the queuing/job tracking, really all you need is to keep track of script runs/jobs somehow and have an HTTP API endpoint which is able to expose this information to your frontend (ie. your Alpine.js widget) through a HTTP call.

Adobe Analytics DTM - Prevent initial server call on specific pages/subdomains?

I'm using Adobe DTM. What I'm trying to figure out is the best way to prevent the initial page load server call from going out on specific pages. The reason is, many parts of our website are 3rd party integrations separated by subdomains. Some of these 3rd party sites are Single Page Applications (SPA). Since most of our site is not a SPA, I need to figure out how to stop the initial server call when I hit one of these subdomains? The vendor is updating the s.pageName variable mapping on their end so I need to prevent the initial call from firing or I'll get two calls initially. I have a data element and event-based rule set-up to detect a change in the page name. I just need to stop it the first time.
Thanks!
In DTM, to prevent that default beacon on page load, you need to put a "return false" statement for those urls somewhere in your Adobe tool code. http://www.digitaldatatactics.com/examples/DCRsuppress.html has an example.

Send form data to local workstation to initiate a Photoshop script with parameters from data

I have a large Photoshop script (written in Javascript) that accepts parameters from me and then generates unique software files and mockups to client specifications. What I would like to do is create a form on the company website for new clients to fill out and then when the form is submitted, have my Photoshop script execute automatically, thus eliminating the need for me to manually enter clients' custom parameters. What I am wondering is if it is at all possible to do this. I would need to somehow track the event as it goes to the server hosting the website and then relay that to my work station. Or, would I have to use my work station as the server (at least for the form)?
I am hitting a wall when it comes to online research so if you don't have an answer, but perhaps have a keyword I have yet to google, that would be appreciated too! Thank you for your time spent reading this.
Details on the "parameters:" The data that needs to be sent consists of Strings and Numbers only. While it is impersonal and does not need encrytion, it could (in some cases) be way to long to fit using the GET method.
Side note: My most current research has lead me to investigate JSON.
I am not sure if I understood your problem :) , but if your problem is to transfer information from server to local machine for processing you can try :
1) store the submitted form on server in file or db,
2) write another script on your local machine that will run every 10 minutes for example (you can do it via cron job in linux) which will grab the new inserted data from server and pass to your photoshop script or store in local machine.
Or you can do by nodejs, I mean
1) the script from local machine connects via socket to the server and listens for new events
2) after each new substitution from website the script receives data from socket and runs photoshop script with given parameters

Dynamic pop up's on a google map by calling a cgi script that runs for ever and return's data after every cycle

I am trying to implement something like google public alerts at institutional level.
I will be displaying the institution map on the home page and if there's an event , I'm trying to insert a marker for that event dynamically i.e., without the user having to refresh the map.
Unfortunately to do this, I have to use a technology called IF-MAP, which forces me to use a cgi script that keeps on repeating cycles till an interrupt is passed.
so this is how my flow is:
web page with google map and ajax script that calls my cgi script for data about the markers
a perl - cgi script that keeps polling the IF-MAP database for any updates on alerts around the campus. by the end of every polling cycle, It returns some data for the web page to bring up markers.
the problem i am facing is,
the web page doesn't bring up the markers until the cgi script finishes it's execution.
Is it possible to insert dynamic alerts on a map using my approach?
if yes, can you please suggest me how?
if no, I've heard about something called socket.io and node.js which make my connection stateful. can these technologies help me work things out?
Thanks.
Can you not just keep it simple?
Poll your IF-MAP database from a cron-job or daemon
Write results to a JSON-formatted file
Make sure webserver caching/timeouts etc are setup correctly for that file
AJAX-GET the results file on a timer allowing the 304 unchanged status to do the hard work for you
You could try and do comlicated stuff with websockets (I think Perl's Mojolicious framework supports them out of the box) but you'll still have the issue of needing a separate process to query this IF-MAP database.

Categories

Resources