Formatting For Generating A Python Script

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information:CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
Goldclownfish
Posts: 15
Joined: Mon Apr 29, 2019 3:50 am

Formatting For Generating A Python Script

Post by Goldclownfish » Mon Apr 29, 2019 4:04 am

:roll:
Last edited by Goldclownfish on Mon May 20, 2019 6:29 am, edited 3 times in total.
Goldclownfish
Posts: 15
Joined: Mon Apr 29, 2019 3:50 am

Re: Formating

Post by Goldclownfish » Tue Apr 30, 2019 2:25 am

:roll: en deleted\")<BR>else:<BR><SP><SP><SP><SP>print(\"The file does not exist\")"[/code]
Last edited by Goldclownfish on Mon May 20, 2019 6:29 am, edited 4 times in total.
chivracq
Posts: 8308
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Formating

Post by chivracq » Tue Apr 30, 2019 3:15 am

Goldclownfish wrote:
Mon Apr 29, 2019 4:04 am

Code: Select all

SET !EXTRACT Login:<SP>{{!COL1}}<SP>Account:<SP>{{mobster}}<SP>{{bankcash}}<BR>{{level}}<SP>Bounty:<SP>{{bounty}}
SAVEAS TYPE=EXTRACT FOLDER=C:\Users\I_AM_\Documents\iMacros\Downloads\CASH\ FILE=CASH.txt

SET cashwebhook "import os<BR>import requests<BR>if os.path.exists("C:\\Users\\I_AM_\\Documents\\iMacros\\Downloads\\CASH\\CASH.txt"):<BR><SP><SP><SP><SP>proxies = {'https': 'http://username:passord@ip:port//'}<BR><SP><SP><SP><SP>txtfile = open('C:\\Users\\I_AM_\\Documents\\iMacros\\Downloads\\CASH\\CASH.txt','r')<BR><SP><SP><SP><SP>postdata = {'file': txtfile}<BR><SP><SP><SP><SP>r = requests.post('https://url', proxies=proxies, files=postdata)<BR><SP><SP><SP><SP>txtfile.close()<BR><SP><SP><SP><SP>print(r.content)<BR><SP><SP><SP><SP>os.remove("C:\\I_AM_\\Documents\\iMacros\\Downloads\\CASH\\CASH.txt")<BR><SP><SP><SP><SP>print("The file has been deleted")<BR>else:<BR><SP><SP><SP><SP>print("The file does not exist")"

SET !EXTRACT {{cashwebhook}}
FILEDELETE NAME=C:\Users\I_AM_\Documents\iMacros\Downloads\CASH\Webhook\webhookcash.py
SAVEAS TYPE=EXTRACT FOLDER=C:\Users\I_AM_\Documents\iMacros\Downloads\CASH\Webhook\ FILE=webhookcash.py
I have created a variable an need to assign this python code to it. I write this code to a file then execute the code in the file via python. If anyone can offer me some assistance with the proper escaping it would be greatly appreciated.

File needs to be written as following

Code: Select all

import os 
import requests 
if os.path.exists("C:\Users\I_AM_\Documents\iMacros\Downloads\CASH\CASH.txt"):	
	proxies = {'https': 'http://username:password@ip:port/'}
	txtfile = open('C:\Users\I_AM_\Documents\iMacros\Downloads\CASH\CASH.txt','r')
	postdata = {'file': txtfile}
	r = requests.post('https://url', proxies=proxies, files=postdata)
	txtfile.close()
	print(r.content)
	os.remove("C:\Users\I_AM_\Documents\iMacros\Downloads\CASH\CASH.txt") 
	print("The file has been deleted") 
else: 
	print("The file does not exist")
Goldclownfish wrote:
Tue Apr 30, 2019 2:25 am
Here is the solution. Sometimes my brain just doesn't function correctly after staring at code for too long. Didn't realize u have to escape " with a \ also. Documentation doesn't really explain what characters u have to escape. Would never have figured this out if i didn't open this code in the imacros editor as i usually use notepad ++ for most things.

Code: Select all

SET cashwebhook "import<SP>os<BR>import<SP>requests<BR>if<SP>os.path.exists(\"C:\\Users\\I_AM_\\Documents\\iMacros\\Downloads\\CASH\\CASH.txt\"):<BR><SP><SP><SP><SP>proxies = {'https': 'http://username:password@url:port//'}<BR><SP><SP><SP><SP>txtfile = open('C:\\Users\\I_AM_\\Documents\\iMacros\\Downloads\\CASH\\CASH.txt','r')<BR><SP><SP><SP><SP>postdata = {'file': txtfile}<BR><SP><SP><SP><SP>r = requests.post('url', proxies=proxies, files=postdata)<BR><SP><SP><SP><SP>txtfile.close()<BR><SP><SP><SP><SP>print(r.content)<BR><SP><SP><SP><SP>os.remove(\"C:\\I_AM_\\Documents\\iMacros\\Downloads\\CASH\\CASH.txt\")<BR><SP><SP><SP><SP>print(\"The file has been deleted\")<BR>else:<BR><SP><SP><SP><SP>print(\"The file does not exist\")"

Yep, very good...!, I'm impressed...! :o
Thanks for sharing...! :D

I would have probably given you the Solution yesterday already if you had mentioned your FCI... (Read my Sig...) :wink:
And yep it is documented in the Wiki, on the Page for 'EVAL()' for example... (+ all Commands needing a Backslash/Forward Slash for File Paths for example).

I still see a "mix" of Spaces and '<SP>' Tags inside or not Double/Single Quotes that might still give some "unexpected" Behaviour, I would think... :|

And you should still mention your FCI and the FCI in which you've tested your Script/Solution, as for example iMacros for FF v8.x/v9.x (I'm not sure about v10.0.2) wraps what is being saved with 'SAVEAS' with Double Quotes which might cause some Pb's for your Python Script... :idea:

[Your Thread will btw probably get moved to the 'General' Sub-Forum as it has nothing to do with 'Data Extraction'...]

Neat Functionality btw, to "misuse" iMacros to create some '.py' Script, ah-ah...! :twisted: Nice...! :D
I use myself a similar Technique to generate '.iim' Scripts and even "auto-morphing" and "AI-enabled" '.iim' Scripts... :wink:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Goldclownfish
Posts: 15
Joined: Mon Apr 29, 2019 3:50 am

Re: Formating

Post by Goldclownfish » Tue Apr 30, 2019 4:21 am

Sorry for not posting my FCI. I've read plenty of your posts an you clearly ask for it in every one. I did in fact fail to read the forum rules an remembered just a bit ago i should probably update the post with the FCI if i expected any response. I do appreciate u commenting on this thou an i posted the answer just so perhaps someday someone else can learn something from it as a vast amount of of the knowledge i have has been gained from your posts chivracq. I was a little unsure where to post this so if it needs to be moved by all means place it where it needs to be. I posted it in data extraction because the full script strips data writes to FILE=CASH.txt an then creates the properly formatted python script. the main iim file is started with a bat file an when it has reached the end the batch file execute the python script an uploads the data thru a proxy via webhook to a server of my choice. i have since cleaned up the missing <SP> also. total iim file is 1337 lines was a little behind on a few things. Haven't noticed an issue with executing it with the <SP>'s but decided to make it Clean.
Last edited by Goldclownfish on Wed May 01, 2019 4:23 am, edited 1 time in total.
chivracq
Posts: 8308
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Formating

Post by chivracq » Wed May 01, 2019 12:57 am

Goldclownfish wrote:
Tue Apr 30, 2019 4:21 am
Sorry for not posting my cim. I've read plenty of your posts an you clearly ask for it in every one. I did in fact fail to read the forum rules an remembered just a bit ago i should probably update the post with the CIM if i expected any response. I do appreciate u commenting on this thou an i posted the answer just so perhaps someday someone else can learn something from it as a vast amount of of the knowledge i have has been gained from your posts chivracq. I was a little unsure where to post this so if it needs to be moved by all means place it where it needs to be. I posted it in data extraction because the full script strips data writes to FILE=CASH.txt an then creates the properly formatted python script. the main iim file is started with a bat file an when it has reached the end the batch file execute the python script an uploads the data thru a proxy via webhook to a server of my choice. i have since cleaned up the missing <SP> also. total iim file is 1337 lines was a little behind on a few things. havent noticed an issue with executing it with the <SP>'s but decided to make it Clean.
Oh...!, very good:
cim Imacros pro v 11.5 Windows 10

"CIM" stands for "Config Info MISSING" btw, I guess you mean "FCI" (= "FULL Config Info")... :wink:
And correct Spelling is "iMacros", not "Imacros"... :wink:

JS inside 'EVAL()' is Case Sensitive for example, you always need to pay attention to "Details" and especially your Spelling, you sound like a "clever" and "creative" User/Programmer (the "perfect" Qualities to do great Things with iMacros actually), but Runtime Engines are always very-very-very stupid, one single mini-Spelling Mistake, and all you get in return is "Syntax Error"...
I'm always very "suspicious" at the Quality of (often self-proclaimed) Super/Advanced Programmers if they can't type any Text without squeezing a Spelling or Grammatical Mistake every 3 Words, can happen in some quick Comment, but not on their Website, which is way too often the case... :oops:

About your Thread Title btw..., "Formating" also contains a Typo/Spelling Mistake, if you could correct it...!? (Correct Spelling is "Formatting"...)
And, hum..., when I had to approve your Post, well "Posts" as I had to disapprove a Duplicate also, I didn't really see how "Formatting" could relate to iMacros and I was pretty sure for 70% that your Post would be from some stupid Spammer... (as about 75-80% of all new Posts are usually Spam actually, and I only approve about 20-25% to become visible on the Forum...), meaning that your Thread Title is not very "explicit" about its Content...
:arrow: But hum, if you could "improve" a bit your Thread Title...?, to make it a bit more "explanatory' than just "Forma[t]ting", by at least mentioning "Python" in it, stg like: "Formatting for generating a Python Script", for example... :idea:
The Content of the Thread is "interesting", it would be a "pity" if other Users don't find/see it because of its "vague" Thread Title... :oops:

Thread already got moved by the Forum Admin to the 'General' Sub-Forum...

And OK, you are using iMB v11.5, so I was right that you were probably not using iMacros for FF v8.x/v9.x... :wink:

And again, very nice Functionality you've implemented with iMacros...! 8)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Post Reply