How to automatically update a site with some other site contents.? - html-content-extraction

How to update a site with some other site contents that is getting refreshed often (may be twice in a minute)?

What you're doing is called scraping a website. Try googling on that. Pay particular attention to the laws around it. If you're benefiting the company you're scraping, they'll probably help you; if you're not, they'll probably sue you.

$.load() is your friend. The following JQuery-function call will replace the current value of element (e.g. div) with the id "result" with the content of page "ajax/test.html".
$('#result').load('ajax/test.html');
or with an additional success handler:
$('#result').load('ajax/test.html', function() {
alert('Load was performed.');
});
if you would like to call one of these function every n seconds, use the following code:
setInterval(function() {
// wrap one of the above calls
}, <n>000);
edit:
for a cross-domain-solution, you can write a proxy page on your site which, upon call, loads the content of the 'other site' and echoes it.
Snippet available here: http://www.daniweb.com/code/snippet216729.html

Related

How do I hide posts with a specific hashtag in Yammer?

I want to hide posts in the feed that have a #joined hashtag. I tried to create a GreaseMonkey script with jQuery in the past, but it couldn't detect any posts that have the #joined text.
Am I using the wrong library? A starting point, or an existing library/plug-in would be helpful.
OFF-TOPIC: At the moment, Yammer does not have any feature to hide posts with a specific hashtag, although it has a feature to follow a hashtag.
I know that this is a pretty old question but I too was trying to create a Chrome based Add-on that hides these #joined posts (or any post with a specific hashtag). I came across this blog https://you.stonybrook.edu/thebaron/2014/10/06/hiding-joined-yammer-posts-in-chrome/ where the author of the post has shared his work (https://gist.github.com/thicknrich/e4cc2871462a6850fe8c). This is a simple javascript and does the job.
//Script from https://gist.github.com/thicknrich/e4cc2871462a6850fe8c
//load jQuery based on this SO Post:
//http://stackoverflow.com/questions/2246901/how-can-i-use-jquery-in-greasemonkey-scripts-in-google-chrome
// a function that loads jQuery and calls a callback function when jQuery has finished loading
function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
// the guts of this userscript
function main() {
// Note, jQ replaces $ to avoid conflicts.
setInterval(function() {
//if a item thread contains #joined, hide it
//check every 5 second.
jQ('.yj-thread-list-item:contains("#joined")').css("display", "none");
}, 5000);
}
// load jQuery and execute the main function
addJQuery(main);
You can find all joined messages with the following endpoint, based upon the #joined topic:
GET https://www.yammer.com/api/v1/messages/about_topic/[:id].json
But you can only delete messsages that you own:
DELETE https://www.yammer.com/api/v1/messages/[:id]
Source: https://developer.yammer.com/restapi/
Note that this is a conscious decision by the product team, although joined messages can get spammy when a network becomes viral, it is a great opportunity to engage users right away once they join. It makes them feel welcome. As a community manager, I'd encourage you to welcome that user in and also encourage other yammer champions to welcome these users also. As a side effect, it also encourages people to follow the groups they are interested in and use the Top or Following feeds instead of the all (firehose) feed which has all these joined messages.
Just want to note that the statement in a reply here "But you can only delete messsages that you own" is not entirely correct it is possible to delete message that do not belong to you if you are a network admin. I just ran a little experiment after reading this post and deleting #joined messages that don't belong to me worked just fine.

Calling a function from injected pagescript in Mozilla Addon SDK

I'm trying to inject a function into a webpage and call it, however no matter how I try it, whenever I try to call the function I get that it's undefined. I understand the browser reads function definitions on the page load and won't do so afterward, but is there a way for me to insert my functions in time. Here's a junk function I'd like to insert:
function makeAlert(word){
alert(word);
}
I've tried to inject it as is, append it to the body with <script> tags, and append it using <script src="makeAlert.js"></script> into the head with page-mod. However whatever I do, if I try to call the function on the page (using injected content script), the function is marked as undefined. Here is the basic code of what I thought would work:
in main.js
pageMod.PageMod({
include: "*",
contentScriptFile: self.data.url("makeAlert.js")
});
edit: as what I want to do seems to not be possible, my simple question is--Can I call a function I wrote from injected pagescript?
Content scripts are kept (mostly) separate from the web page for security reasons, see
https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Content_Scripts
If you really want to do this, you can by instead doing:
unsafeWindow.makeAlert = function (word){
alert(word);
}
A couple of important things about doing things this way:
unsafeWindow is, well, UNSAFE. Never trust any data that come from unsafeWindow, ever.
it will go away some time this year ( unsure of the exact timing )
What you should probably do instead is using postMessage from the web page to the content script to pass mesages. For more on how to do this safely, please read these docs:
https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Content_Scripts/Communicating_With_Other_Scripts#Page_Scripts

How to make wp plugin auto-refreshing on the public side of view (auto load page)

First have to say that almost every time when searching on technical solutions.. search engine will direct me to this site here. I admit that i have learned such A LOT here just by searching through for answers..
but also have to say that not being a coder.. so don't understand much here at all ;)
Ok, the Problem:
Want to update wordpress tables or calendar within wp admin. These changes should become updated on the public side automatically and more or less instantly (~ few seconds is perfectly fine).
I found solutions about manipulating header.php, i found some ajax plugins I found -too much to count- info on how to implement ajax into wp
Sadly.. none of these could help me through as the plugins mostly either not work, are outdated or require countless file edits. Manipulating header.php seems odd.. as i don't want to loop-refresh the whole page, post etc.. but only get e.g. table or calendar data updated.
So maybe any of you coders know of something to e.g. get the plugin "All-in-One Event Calendar by Timely" to update the public visible part of the calendar once data edited in wp admin?
Greatly appreciate pointers in any direction to solve this.
P.S.: What would you think of plugins like "ajaxify everything" ? don't know if this really the way to go..
Again, thanks for your help, time and contribution!!
update
additional question:
I now found such plugin to let me chose which parts i want to "ajaxify".
Such plugin would ask me for a specific function name.
Now, where do i start to gather this information?
Below is the instruction from the plugin context inside wordpress admin
Generate Ajaxized DIV for your function
Ajaxize will allow you to ajaxize almost any php function on your
site.
It can be a plugin, a function you wrote, or even a core wordpress
function.
There are some (obvious or less obvious) limitations currently:
Functions must return valid HTML - this will be called in php and returned via the
Ajax call
Functions cannot accept any parameters (at least at the moment)
Enter a function name below.
Function Name: xxx input field xxx what put in here? xxx
The generated div can be inserted to any page/post on the site and
will ajaxize the call to the function automatically.
Please make sure you enter a valid function name, that the function
does not require any parameters, and that it returns valid HTML.
In your context you want to refresh the calendar automaticaly when there is a change in the WP_Admin;
but you can't exactly do this.
You can write a Js method which will check the time of lastest modification of the calendar at the load of the page, stock it in Var.
After you'll have a constant (each 10seconds) Js "daemon" which will get the time of lastest modification of the calendar and compare it to the stocked Var; If change you reload the calendar.
PS: Ajaxify everything is not really a solution due of the developpement you need To Ajaxify and to code for people who has disabled Javascript.
Hope it helps

django update page when database field updates?

I have a results page and I am trying to work out how to auto update the page when an external database field is updated. I have seen quite a few examples but they seem to relate to PHP. I have a test that calls various APIs that can take up to an hour to complete. Once the test has completed, it will enter a success or failed message in a database field.
I already have my results page being rendered by django using template tags. I have a table and I have the field I would like to update. There are multiple fields that need update which correspond to each API test.
I have seen this site.. is this the kind of stuff to use? http://www.dajaxproject.com/ Is this an easy task to do? Does anyone have any ideas on how to do this?
Sorry but I don't know where to start on this one.
Cheers - Oli
I decided not to be so bold and just use the old classic page update for this purpose using javascript..
window.onload = setupRefresh;
function setupRefresh() {
setTimeout("refreshPage();", 30000); // milliseconds
}
function refreshPage() {
window.location = location.href;
}
Still open for options however I'm rather inexperienced in django and maybe this was too much to bite off too quickly..

how count downloads of a file with jquery

Anyone knows some jquery plugin to count how many times a file (pdf, in my case) is download from your server??
you can simply use the google analytics javascript API with an onclick event
Then you can have beautiful charts for your downloads. see here for an example case : http://think2loud.com/use-jquery-with-google-analytics-to-track-clicks-on-outgoing-links-from-your-site/
You can create script download.php that count your download links.
<?php
// connect to database
if (isset($_GET['file'])) {
$file = mysql_real_escape_string($_GET['file']);
$query = "insert into downloads VALUES('$file', 1) on duplicate key " .
"update count = count + 1;, count+1)";
mysql_query($query);
}
?>
downloads table is:
create table downloads(file VARCHAR(255) primary key, count integer default 1)
and in jQuery
$('a.download').click(function() {
//empty function don't care what I get.
$.get('download.php', {file: $(this).attr('href')}, function() {});
});
it call download.php script with href attribute on every link that have download class
UPDATE I forget to add return false because in code above it call ajax and then abort it.
$('a.download').click(function() {
var link = $(this).attr('href');
$.get('download.php', {file: link}, function() {
// change url to link when ajax is finished
window.location = link;
});
// prevent following the link
return false;
});
You can also add code that prevent multiply clicks because there will be delay between ajax call finish and changing url to link of a element (user may click few times because it will not folow the link) and you can add CTRL+click because it open link in other window (you can return true in this case).
You can use jQuery to determine how many times a single user clicks on a given link on a given fully-rendered page, and use that value to update a database table of download clicks through AJAX, but jQuery doesn't have any direct insight into your server-side data as relates to the total number of downloads, you would have to be updating a database with that data and displaying it from there. you could use jQuery to watch and see if that value changes (on a timer maybe) and update your page accordingly, butthat still requires a AJAX call to a database lookup.
jQuery is a library for Javascript with is a client-side language and acts on the page once it is downloaded and running on the client's machine and as such is not the place for server-side logic and lookups except in the cases where AJAX is warranted and needed.
This is impossible. jQuery code runs in a user's browser, not on a server. To count downloads you'll need server-side code.
jQuery alone won't be able to do that.
You would have to keep track on the server each time the file is requested.
Is there anyway to modify the above script to allow only 1 download per user in a set period of time based on the date they joined the site, i.e. the user can only download the file once per year starting from the day they joined the site?
I'm using Wordpress to run my site.
Thanks

Resources