Zapier Python or Javascript Code for Twitter HTML - javascript

I'm using Zapier to run a search on Twitter, create a daily digest of results (Zapier Digest), and send the digest to a mailing list (Mailgun). I seek to format the Tweets similar to Twitter's own emails where the tweet isn't text but HTML where any user mention (#name, corresponding URL is https://twitter.com/[NAME]) and URL in the tweet are actual links. (I don't want the conversion for any hashtags.)
This search, extract, and replace (with added HTML) isn't that hard. But it's too much for Zapier's simple Formatter text functions. So I turned to the Zapier Code action, thinking I could borrow code as I'm not a hardcore coder.
I found Python code as below (and others at that site). After a couple hours of testing I've given up on being able to successfully adapt it for use in Zapier Code. Zapier has limitations on how it uses Python. Their documentation on it is primitive.
Could someone here familiar with Zapier help me with converting that (or similar) code so I could run it on Zapier Python or Javascript? I truly would appreciate it.
Thank you,
Marc
https://coderwall.com/p/wdtkhw/convert-links-username-mentions-and-hashtags-in-a-tweet
function twitterify($ret) {
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1\\2", $ret);
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1\\2", $ret);
$ret = preg_replace("/#(\w+)/", "#\\1", $ret);
$ret = preg_replace("/#(\w+)/", "#\\1", $ret);
return $ret;
}

David here, from the Zapier Platform team.
Marc, your main problem is that you're using a PHP snippet in our Python interpreter, which is probably why it's giving you trouble. If you have specific questions or there's something we can improve about our documentation, definitely let me know!
I'd check out the python re.sub() function instead. There's a great answer about it here. You'll also want to be able test your regex, for which there's a great site (as there are some sleight differences between PHP and Python regex. There's also a great language resource here if you want to learn more about the Python language.
​Let me know if you've got any other questions!

David,
Regarding documentation, the help page is oriented to someone who has Python or Javascript experience. I don't. The following would help.
In-code commenting. For the most part, the help just says here's what an example does and shows the code. It doesn't explain what each line of code does.
The help virtually skips to advanced examples, such as comma
separated lists. More basic examples would provide firmer ground
for newbies like me.
I continued testing and came up with the following code for Zapier Python, based on the snippet above. While it executed without error (progress!), it made no change to the #user or URL in the input data test tweet.
Marc
import re
tweetHTML = re.sub('/#(\w+)/', '#\\1', input_data ['tweet'])
tweetHTML = re.sub('#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#', '\\1\\2', tweetHTML)
tweetHTML = re.sub('#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#', '\\1\\2', tweetHTML)
return {'tweetHTML': tweetHTML}

Related

How this JS code is working and what form it is encoded in?

I have been developing Data Scraping scripts for past 3 years but never had tough time like this.
I am scraping a site, To prevent scraping, it shows message Please enable JS in your browser
But then there is JS code that creates some sort of cookie or token, and redirects to the actual page.
https://pastebin.com/BL95Z48C
I only want to know what form that code is encoded? How can I decode it?
The code has been obfuscated using some kind of JavaScript Obfuscator.
Here is the de-obfuscated / decoded version of that code ... p­astebi­­n­.com/­Rjcge­Tfs
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
so. what did i do so far?
i took your code, threw it in jsnice.org and jsbeautifier.org
i noticed two code blocks wrapped in eval functions. i simply took them out of the evals and copied the code blocks into jsnice again.
from there i did this:
code.replace(/\/\*.+\*\//g, '')
.replace(/(?:\$|to8bitStream)\(([\d, ]+)\)/g, (a,b) => JSON.stringify(b.split(', ').map(x=>String.fromCharCode(x-63)).join``))
.replace(/(?:key|get)\((\d+)\)/g, (a,b) => JSON.stringify(parseInt(b,10).toString(36)))
.replace(/get\(0x([\da-f]+)\)/gi, (a,b) => JSON.stringify(parseInt(b,16).toString(36)))
.replace(/(?:forEach|createDom)\((\d+)\)/g, (a,b)=>746>parseInt(b))
.replace(/(?!=\s*)\["([a-z\d_]+)"\]/gi, (a,b)=>'.'+b);
to get a modified version of that code that i then threw just back into jsnice to get the following output:
https://gist.github.com/GottZ/ce2f7dea949b2b7af64606426e56adde
i'll now be afk for some minutes and will continue deobfuscating that securemsg stuff.
PS: keep in mind i'm doing this for free.

google plus login gPlus id check?

On the google developers serverflow documentation here:
https://developers.google.com/+/web/signin/server-side-flow
It says that you must validate the userid gotten from the server with the one send in by the client.
if ($tokenInfo->userid != $gPlusId) {
return new Response(
"Token's user ID doesn't match given user ID", 401);
}
However, I am not sure how the client javascript is supposed to know what the google id is. I'm pretty sure its now part of the callBack's authresult.
The only way I can think of is if the client itself made calls to google to get it's own googleid.
What is the correct way to do this?
Thanks
Short Answer ( from my reading ) --
gplus_Id authentication isn't needed and can leave that step
Long Answer and references.
I found some answers during my readings. As it happens the java quick start application guide has the gplus_Id but the php one does not. Yet the single sign in flow is using it as you mention above ( in step 8 ). The google discussion here mentions that --- " See the slightly related discussion here: https://github.com/googleplus/gplus-quickstart-php/pull/7
The gplus_id is usually send from the client to the server together with the one-time code, but it doesn't really add anything in extra security, so it was removed from the php example.
But yeah, the documentation should be adjusted to match the current sample code.
(And the Java quickstart sample has been updated and doesn't send the gplus_id anymore either...)" .
I hope it helped :).

is it possible to obfuscate while using soma.js dependency injection?

While looking at how to make JavaScript source code more secure I came upon a lot of 'solutions'. but most people said the same thing; "It's not possible to make your source code 100% secure", "try obfuscation", "run your code server side", etc, etc. After reading a lot posts here on stackoverflow, and other sites I came to the conclusion that a combination of minifying and obfuscating would do the job (for me).
But here is the problem: we are currently using soma.js with dependency injection, and the way we set it up it does not work well with obfuscation. It's basically this:
var session = function(id, sessionModel){
this._sessionmodel = sessionModel;
}
mapping:
injector.mapClass("sessionModel", project.SessionModel, true);
Obfuscation will then rename the sessionModel in the function to for example 'A', but the mapping that was done on SessionModel by the injector still remains 'sessionModel' and not 'A', this then basically breaks the code.
I've read this post which is about the same subject Dependency Injection and Code Obfuscation, but it does not provide a real answer to my problem so I decided to write my own question.
Any tips/hint/suggestions are welcome.
Thanks in advance.
EDIT
It seems you can tell Yuicompressor to exclude certain identifiers by putting in 'hints' into the files like this: "identifier:nomunge, identifier2:nomunge".
var session = function(id, sessionModel){
"sessionModel:nomunge";
this._sessionmodel = sessionModel;
}
I tested this and it works but that means you'll have to put it in yourself which is a lot of work if you have to do that for every script, especially if you have a very big project..
Gonna look into it further, and update this post if anything new pops up
EDIT 2
It's been a while, I only work 1 day a week on this =S.
As said before you can get it working by telling it which identifiers to exclude.
For that I looked into regular expression to get the "mapped classes" programmatically, since doing it by hand is just insane.
What I basically did was instead of putting every hint in by hand, I made a identifier, for example "#nomunge"; and used a simple replaceregexp task to find it and replace it with a string containing all the identifiers. This string is build by loading the script and going through it with a tokenfilter.
<target name="build hints">
<loadfile property="hints" srcFile="${temp.loc}/all.js">
<filterchain>
<tokenfilter delimoutput=":nomunge,">
<ignoreblank/>
<containsregex pattern="${regexp}"/>
</tokenfilter>
</filterchain>
</loadfile>
<echo message="${hints}"/>
</target>
<replaceregexp file="${temp.loc}/all.js"
match="#nomunge"
flags = "g"
replace = "target:nomunge, dispatcher:nomunge, injector:nomunge,${hints}"
/>
This seems to do the job, for now...
I'm behind the soma.js framework, feel free to ask me questions on the google group, happy to help.
This might help a bit more:
https://groups.google.com/forum/#!topic/somajs/noOX2R4K58g
Romu

How would I solve a coding puzzle with Javascript?

There is a website called Gild.com that has different coding puzzles/challenges for users to do. They can be completed in wide array of languages including Javascript. I am interested in solving these puzzles in Javascript, but I am unsure of the following:
How am I supposed to access the input file which is supposed to be passed as an argument?
How am I supposed to output the result?
My understanding of Javascript is that it is run from within an HTML page and that output really is only in the form of placing values in the HTML, modifying the DOM, etc. For that reason it is not clear to me how Javascript can be used for solving these types of problems. Can someone who has used Gild before or has some insights into my question suggest how to proceed?
An example of a problem would be: the given input file contains a positive integer, find the sum of all prime numbers smaller than that integer and output it.
EDIT: Some of the solutions below involve using external resources, but on Gild, I am supposed to put my solution in their editor and then submit it that way, like the following picture shows:
In other words, I don't think my solution can have access to Node.js or other external resources.
Edit: Here are some interesting articles that I have found that I think are the answer to my question:
http://www.phpied.com/installing-rhino-on-mac/
http://www.phpied.com/javascript-shell-scripting/
I haven't spent much time on Gild, but I do a lot of similar types of problems on Project Euler. I think the best way to go is probably Node.js.
If you're not familiar, Node is basically server-side JavaScript that runs in Google's V8 engine. Installing it on your own Mac/Windows machine takes about 2 minutes. It's also really fast (considering it's JavaScript).
And you'd use it like this:
var fs = require('fs'); // the filesystem module
var contents = fs.readFileSync('theFile.txt', 'utf-8');
// Do stuff with the file contents...
Everything after those first two lines can be done with the same JS you'd write in the browser, right down to calling console.log() to spit out the answer.
So, if you wrote your script in a file on your desktop called getprimes.js, you'd open up your terminal and enter node ~/Desktop/getprimes.js (assuming you're on a Mac)
If you're:
on a Mac,
planning to do a lot of these puzzles, and
willing to pay $10, then
I highly recommend CodeRunner. It encapsulates runtimes for a variety of languages — from C to JavaScript — and lets you quickly build and run any sort of one-off code. Just hack together your code, ⌘R, and the results are printed right there in the same window.
I haven't used any file-based JavaScript in CodeRunner, but I imagine kennis's suggestions would apply. To output your results:
console.log(...)
Easy as pie!

What does XLLS mean?

Is there some relation between "XLLS" expression and AJAX / Javascript? What does the XLLS actually mean?
Thanks in advance
adding text from a comment below an answer
...the only result I got when I was looking for an answer on Google was the Excel XLLs but nothing related to JS. It's because I'm learning for an exam and there is a question to describe acronym "XLLS". Maybe typo?
Never heard of that in a Javascript context.
The only meaningful Google result I can see is Developing Excel 2010 XLLs
Sure you don't mean XSLT? or XSS?

Categories