Randomizing URL numbers in iMacros - web-scraping

I'm using iMacros because I want to scrape a certain site for ID's which are used in the URL, after which I want to press a button.
I know you can't use Regular Expressions or globbing in the syntax for URL GOTO.
But I figured there might be a way to enter variables into the URL GOTO=?
Preferable I wouldn't want to randomize the variable, but have it try every page from [1 - 99999]
This is what I currently have:
VERSION BUILD=8940826 RECORDER=FX
TAB T=1
SET !ERRORIGNORE YES
SET !VAR3 ("Math.floor(Math.random()*99999 + 1);")
URL GOTO=http://example.com/id/ "randomized_variable_here"
TAG POS=1 TYPE=SPAN ATTR=TXT:press<SP>button
I have tried a few things, but I don't seem to be able to do this.
I have very little experience actually creating stuff for myself, I just modify scripts to fit my purposes, but should I look towards an HTML document or something like that to randomize that variable for me?
Thanks in advance!

It's pretty simple to get the string with a randomized variable:
' ...
SET !VAR3 EVAL("Math.floor(Math.random()*99999 + 1);")
URL GOTO=http://example.com/id/{{!VAR3}}
' ...
And the following code is for looping through [1 - 'Max:' value on the 'iMacros' sidebar]:
' ...
SET !LOOP 1
URL GOTO=http://example.com/id/{{!LOOP}}
' ...
Just play this macro in loop mode.

Related

Get Next and Previous Tags (AwesomeWM)

Is there a way to get the next or previous tag in AwesomeWM Lua Config?
Reason :- I want to get the next or previous tag to set the focused clients tag to it and then move to the tag.
I know there is awful.tag.viewnext which moves to the next tag but unsure about how to get the tag it will move to to set this on a client.
Thanks in advance
Well... yes, there is a way, but there is not a completely trivial one.
First, let's look at the default config. What existing functionality has to get next/previous tags? That is the mouse wheel on the taglist:
https://github.com/awesomeWM/awesome/blob/7a759432d3100ff6870e0b2b427e3352bf17c7cc/awesomerc.lua#L160-L161
So, how does awful.tag.viewnext and viewprev get the next tag? These functions just call viewidx with an idx of 1 or -1, e.g.:
https://github.com/awesomeWM/awesome/blob/7a759432d3100ff6870e0b2b427e3352bf17c7cc/lib/awful/tag.lua#L1494
So, awful.tag.viewidx can do what we want. How does it do it?
It gets a table of all un-hidden tags, finds the index of the currently selected tag and then uses gears.math.cycle to compute the index of the tag with the requested offset.
https://github.com/awesomeWM/awesome/blob/7a759432d3100ff6870e0b2b427e3352bf17c7cc/lib/awful/tag.lua#L1452-L1469
For you, something like the following should do the trick:
function get_tag_at_offset(i, s)
s = screen[s or awful.screen.focused()]
local tags = s.tags
local showntags = {}
for _, t in pairs(tags) do
if not awful.tag.getproperty(t, "hide") then
table.insert(showntags, t)
end
end
for k, t in ipairs(showntags) do
if t == sel then
return showntags[gears.math.cycle(#showntags, k + i)]
end
end
end
The above function can be used like get_tag_at_offset(1) to get the next tag and with argument -1 for the previous. Where possible, I would recommend to also pass in a screen via the second argument.
Also, all of this is completely untested and just written on the spot. There could very well be typos and other mistakes in here.

Meteor - Passing a jade helper into a helper function

I'm trying to populate a list with a dataset and set the selected option with a helper function that compares the current data with another object's data (the 2 objects are linked)
I made the same type of list population with static variables:
Jade-
select(name='status')
option(value='Newly Acquired' selected='{{isCurrentState "Newly Acquired"}}') Newly Acquired
option(value='Currently In Use' selected='{{isCurrentState "Currently In Use"}}') Currently In Use
option(value='Not In Use' selected='{{isCurrentState "Not In Use"}}') Not In Use
option(value='In Storage' selected='{{isCurrentState "In Storage"}}') In Storage
Coffeescript-
"isCurrentState" : (state) ->
return #status == state
This uses a helper isCurrentState to match a given parameter to the same object that my other code is linked to so I know that part works
The code I'm trying to get to work is :
Jade-
select.loca(name='location')
each locations
option(value='#{siteName}' selected='{{isCurrentLocation {{siteName}} }}') #{siteName}
Coffeescript-
"isCurrentLocation": (location) ->
return #locate == location
All the other parts are functioning 100%, but the selected part is not
I've also tried changing the way I entered the selected='' part in a manner of ways such as:
selected='{{isCurrentLocation "#{siteName}" }}'
selected='{{isCurrentLocation "#{siteName} }}'
selected='{{isCurrentLocation {{siteName}} }}'
selected='#{isCurrentLocation "{{siteName}}" }'
selected='#{isCurrentLocation {{siteName}} }'
selected='#{isCurrentLocation #{siteName} }'
Is what I'm trying to do even possible?
Is there a better way of achieving this?
Any help would be greatly appreciated
UPDATE:
Thanks #david-weldon for the quick reply, i've tried this out a bit and realised that I wasn't exactly clear in what I was trying to accomplish in my question.
I have a template "update_building" created with a parameter( a buidling object) with a number of attributes, one of which is "locate".
Locations is another object with a number of attributes as well, one of which is "siteName". One of the siteName == locate and thus i need to pass in the siteName from locations to match it to the current building's locate attribute
Though it doesn't work in the context I want to use it definitely pointed me in a direction I didn't think of. I am looking into moving the parent template(The building) date context as a parameter into the locations template and using it from within the locations template. This is easily fixable in normal HTML spacebars with:
{{>locations parentDataContext/variable}}
Something like that in jade would easily solve this
Short answer
selected='{{isCurrentLocation siteName}}'
Long answer
You don't really need to pass the current location because the helper should know it's own context. Here's a simple (tested) example:
jade
template(name='myTemplate')
select.location(name='location')
each locations
option(value=this selected=isCurrentLocation) #{this}
coffee
LOCATIONS = [
'Newly Acquired'
'Currently In Use'
'Not In Use'
'In Storage'
]
Template.myTemplate.helpers
locations: LOCATIONS
isCurrentLocation: ->
#toString() is Template.instance().location.get()
Template.myTemplate.onCreated ->
#location = new ReactiveVar LOCATIONS[1]
I looked into the datacontexts some more and ended up making the options that populate the select into a different template and giving that template a helper, accessing the template's parent's data context and using that to determine which location the building had saved in it so that I could set that option to selected
Jade-
template(name="location_building_option")
option(value='#{siteName}' selected='{{isSelected}}') #{siteName}
Coffeescript -
Template.location_building_option.helpers
'isSelected': ->
parent = Template.parentData(1)
buildSite = parent.locate
return #siteName == buildSite
Thanks #david-weldon, Your answer helped me immensely to head in the right direction

Maya MEL shelfbutton

I am pretty new to MEL and as I was exploring around this MEL script, I found out that the user have write some lines that I totally do not get it.
And yet I am interested to know why this person done it..
Anyway, can someone kindly explain why does the following code, first indicate an empty MEL then it goes on to call a Python? Wouldn't it be easier to just put in the Python?
I also tried to disable the command and sourceType, and the script works fine too, it is just that I do not get what is the purpose of command and sourceType doing in this case...
-command ""
-sourceType "mel"
-actionIsSubstitute 0
-commandRepeatable 1
("shelfBtn_" + $parent + "_AOV");
python("import aovsFunction as aovs; aovs.MenuFuncs.aovMenu('"+"shelfBtn_" + $parent + "_AOV"+"')");
By the way, $parent is derived from:
global proc apkg2dnc(string $parent)
Then I tried to change the code into the following, it works as like the one above but...
-command ("import aovsFunction as aovs; aovs.MenuFuncs.aovMenu('"+"shelfBtn_" + $parent + "_AOV"+"')")
-sourceType "python"
When I tried removing the brackets, I was given the Syntax Error message, indicating the first plus sign + that it encounters.
Did tried to add in the ; at the end of the line, it is still giving the Syntax Error, this time indicating at the start of the line
-command "import aovsFunction as aovs; aovs.MenuFuncs.aovMenu('" + "shelfBtn_" + $parent + "_AOV" + "')"
-sourceType "python"
And so, does brackets play a big part in how it is being read in MEL?
Your examples are malformed. In general you can not cut code from switches like you are doing because the code looses meaning. Switches like:
-command ""
are referring to the line before where the actual mel command is invoked (not to be confused with the -command switch). In this case i would guess the entire command is actually:
shelfButton
-command ""
-sourceType "mel"
-actionIsSubstitute 0
-commandRepeatable 1
("shelfBtn_" + $parent + "_AOV");
But it is hard to know. The code looses all meaning if you omit the command being called and can for most part not be understood that way as it has no meaning. Its like a sentence without a subject, predicate and context.
With that clarified we can actually answer the question. Why put a a empty -command? Its a bit redundant, yes but it still has meaning. The reason is that he does not know what to populate the button with. You could omit the command and source type flags shouldn't make a difference. (there is a off chance that omitting source type would end up being subtly wrong)
The next command does the binding:
python(...yada yada ... "('"+"shelfBtn_" + $parent + "_AOV"+"')");
No i have no idea what aovMenu really does but the intention is pretty clear because he is passing the name of the button. Whatever is inside the aovMenu command is changing the command of the button. This would off end up looking like it worked if you put it into -command switch directly (because pushing the button the first time would populate the button). But it would be subtly wrong, nonetheless.
This is a pretty common pattern in maya programming. What you do is you pre-generate the button to know its final name so that you can bind two entities that depend one each other to that name.
goes on to call a Python? Wouldn't it be easier to just put in the Python?
Not really the code would be exactly the same. It might be easier this way, depends on who is calling. You would still need to bootstrap the button and then call the aovMenu function. Its not really any different form calling a function made by somebody else.
The thing is the code is a bit bad, there is a small chance for a subtle error. It wouldn't matter if it was written in python or not but rather how Maya behaves. You can not actually know the button will be called:
("shelfBtn_" + $parent + "_AOV")
Because if that name exists maya will rename it OR worse name it the same as something else and now you have to use the full path name or get a 50% chance of error. the correct way to do this would be thus:
$sButton = `shelfButton
-actionIsSubstitute 0
-commandRepeatable 1
("shelfBtn_" + $parent + "_AOV")`;
python("import aovsFunction as aovs; aovs.MenuFuncs.aovMenu('"+$sButton+"')");

# symbol in Drupal modules

I'm trying to learn Drupal modules. Can someone tell me what the '#' symbol is? I dont remember coming across it in PHP. (Its tricky to search for it cos as far as I can tell, you cant google for symbols). Can I convert it into a normal PHP variable, modify it and finally put it back into an # thing within the PHP of the .module file?
UPDATE: e.g.:
$error['msg'] = t("We're sorry. We have now only #qty of the ....
in file...
http://drupal.org/project/uc_out_of_stock
While that is the case in general PHP, it is used differently in Drupal within the t() function.
You can properly use placeholders in your text (which should be wrapped in t() for translation purposes on i18n capabilities) by putting a # , ! or % in front.
! = insert as is
# = run text through check_plain
% = html escape text
More info on the API page
In PHP the # symbol suppresses error messages.
There's plenty about it in the manual. When in doubt that's the place to go.
http://us3.php.net/manual/en/language.operators.errorcontrol.php

open graph image url problems with converted special chars XKB Symbols

I try to use the like-Button and therefor the open graph.
My problem is, that "&" and "$" chars are always replaced by & and %24
Of course, thats the normal case, but I need a clean $ and no entity there, becuase otherwise the link is not working for this image.
I could see, that facebook´s raw output produces \u0024 and so on (seems to be XKBSymbols). But if I try to put this symbols in the link in my typo3 meta-tag, it doesnt work either.
I already tried:
#page.headerData.12345.htmlSpecialChars = 0
#page.headerData.12345.htmlSpecialChars.preserveEntities = 1
#page.headerData.12345.rawUrlEncode = 0
to solve this problem, but none of those work.
Please give me a useful hint.
Thanks
try to write to your php code trough htmlspecialchar php function and add it to header with
$GLOBALS['TSFE']->additionalHeaderData['somekey'] = '...'

Resources