I want to know why I cannot use this function? - function

yahoo<-function(sym,current = TRUE, a=0,b=1,c=2000,d,e,f,g="d")
{
if(current){
f<-as.numeric(substr(as.character(Sys.time()),start = 1,stop = 4))
d<-as.numeric(substr(as.character(Sys.time()),start = 6,stop = 7))-1
e<-as.numeric(substr(as.character(Sys.time()),start = 9,stop = 10))
}
require(data.table)
tryCatch(
suppressWarnings(
fread(paste0("http://ichart.yahoo.com/table.csv",
"?s=",sym,
"&a=",a,
"&b=",b,
"&c=",c,
"&d=",d,
"&e=",e,
"&f=",f,
"&g=",g,
"&ignore=.csv"),sep=",")),
error = function(e) NULL
)
}
When I run Google<-yahoo("GOOG"), this is the message I received:
trying URL 'http://ichart.yahoo.com/table.csv?s=GOOG&a=0&b=1&c=2000&d=8&e=13&f=2017&g=d&ignore=.csv'
Content type 'text/html; charset=utf-8' length unknown
downloaded 1078 bytes
So how to change that function make it work?

This code isn't working because the Yahoo Finance web service which you're trying to access was discontinued in May 2017. You will need to find another source for this data.

Related

How to search registered user on ejabberd server from client side using smack library?

I am using smack on the client-side. I tried to search registered users on the client-side because before creating a new user I want to know that the id is registered on server or not if not then create the user either log in the user but ejabberd server crashed with the error. Here are the crash logs of ejabberd server.
Failed to process iq:
#iq{
id = <<"Hh6AJ-28">>,type = set,lang = <<"en">>,
from =
#jid{
user = <<"admin">>,server = <<"faiqkhan-virtualbox">>,
resource = <<"92526029764259513741138">>,luser = <<"admin">>,
lserver = <<"faiqkhan-virtualbox">>,
lresource = <<"92526029764259513741138">>},
to =
#jid{
user = <<>>,server = <<"vjud.faiqkhan-virtualbox">>,resource = <<>>,
luser = <<>>,lserver = <<"vjud.faiqkhan-virtualbox">>,lresource = <<>>},
sub_els =
[#xmlel{
name = <<"query">>,
attrs = [{<<"xmlns">>,<<"jabber:iq:search">>}],
children =
[#xmlel{
name = <<"x">>,
attrs = [{<<"xmlns">>,<<"jabber:x:data">>},{<<"type">>,<<"submit">>}],
children =
[#xmlel{
name = <<"field">>,
attrs = [{<<"var">>,<<"user">>},{<<"type">>,<<"text-single">>}],
children =
[#xmlel{
name = <<"value">>,attrs = [],
children = [{xmlcdata,<<"wasiq#faiqkhan-virtualbox">>}]}]}]}]}],
meta = #{ip => {0,0,0,0,0,65535,49320,11092}}}
exception error: {module_not_loaded,mod_vcard_mnesia,
<<"faiqkhan-virtualbox">>}
in function gen_mod:get_module_opts/2 (src/gen_mod.erl, line 338)
in call from gen_mod:get_module_opt/3 (src/gen_mod.erl, line 318)
in call from mod_vcard_mnesia:filter_fields/3 (src/mod_vcard_mnesia.erl, line 200)
in call from mod_vcard_mnesia:search/4 (src/mod_vcard_mnesia.erl, line 78)
in call from mod_vcard:search_result/4 (src/mod_vcard.erl, line 479)
in call from mod_vcard:process_search/1 (src/mod_vcard.erl, line 264)
in call from gen_iq_handler:process_iq/3 (src/gen_iq_handler.erl, line 131)
in call from gen_iq_handler:process_iq/4 (src/gen_iq_handler.erl, line 109)
I used the following code to get a registered user from the client-side:
InetAddress address = InetAddress.getByName(HOST);
DomainBareJid serviceName = JidCreate.domainBareFrom("faiqkhan-VirtualBox"); XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();
builder.setPort(PORT);
builder.setSendPresence(true);
builder.setHostAddress(address);
builder.setServiceName(serviceName);
builder.setUsernameAndPassword("admin", "123456");
builder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
XMPPTCPConnection connection = new XMPPTCPConnection(builder.build());
try {
connection.connect();
connection.login("admin", "123456");
Logger.showError("21560-connection created to: " + connection.getHost());
Roster roster = Roster.getInstanceFor(connection);
Set<RosterEntry> entities = roster.getEntries();
UserSearchManager search = new UserSearchManager(connection);
DomainBareJid s = JidCreate.domainBareFrom("vjud.".concat("faiqkhan-VirtualBox"));
Form searchForm = search.getSearchForm(s);
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("user", "wasiq#faiqkhan-virtualbox");
ReportedData data = search.getSearchResults(answerForm, s);
if (data.getRows() != null) {
for (ReportedData.Row row : data.getRows()) {
for (CharSequence value : row.getValues("jid")) {
Log.i("Iteartor values......", " " + value);
}
}
}
} catch (SmackException | IOException | XMPPException | InterruptedException e) {
Logger.showError("21560-error on account creation: " + e.getMessage());
}
Server crashed on ReportedData data = search.getSearchResults(answerForm, s); line of code.
You found a bug in ejabberd:
It was already fixed in 2018 in
https://github.com/processone/ejabberd/commit/1be21126342d503205798605725ba5ceef9de42b
but the bug got reintroduced in 2019 in
https://github.com/processone/ejabberd/commit/a02cff0e780bb735531594c4ece81e8628f79782#diff-71f613241ed580c3e5dad2b4526503f2R12
and I've now applied a temporary fix in
https://github.com/processone/ejabberd/commit/92913389a51ddc564f11e0712b0d82fca8c9aecb
But even if that bug is fixed, the feature you want to use probably doesn't help: a user must set his vCard in order for his account to be provided in vJud search. In other words, vJUD searches in stored vCards, not in registered accounts. If I register an account but don't set a vCard, then vJUD will not find it.
before creating a new user I want to know that the id is registered on server or not
And why don't you simply attempt to register the account first?
On the other hand, if you would like to check in advance if an account is available for registration or not (like some web registration sites do, to allow the user modify the username until one is available), then I think XMPP doesn't provide that possibility for security reasons: it is not allowed to know if an account exists or not.
A solution for that would be to use the check_account ejabberd command
https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#check-account
executing it with some frontend, like ejabberdctl, ReST or XMLRPC
https://docs.ejabberd.im/admin/guide/managing/#ejabberd-commands
$ ejabberdctl check_account user1 localhost
$ ejabberdctl check_account user6666 localhost
Error: false
~ 1

I'm having trouble with sending a form using POST to retrieve data in R

I'm having trouble collecting doctors from https://www.uchealth.org/providers/. I've found out it's a POST method but with httr I can't seem to create the form. Here's what I have
url = url = 'https://www.uchealth.org/providers/'
formA = list(title = 'Search', onClick = 'swapForms();', doctor-area-of-care-top = 'Cancer Care')
formB = list(Search = 'swapForms();', doctor-area-of-care = 'Cancer Care')
get = POST(url, body = formB, encode = 'form')
I'm fairly certain formB is the correct one. However, I can't test it since I yield an error when trying to make the list. I believe it is because you can't use "-" characters when naming although I could be wrong on that. Could somebody help please?
I am unable to comment properly but try this to create an list. Code below worked for me.
library(httr)
url = 'https://www.uchealth.org/providers/'
formB = list(Search = 'swapForms();', `doctor-area-of-care` = 'Cancer Care')
get = POST(url, body = formB, encode = 'form')
When you are creating names with spaces or some other special character you have to put it into the operator above.

JSON Parse error: Unrecognized token '<'

I am getting this error (as per Safari's Web inspector) but I cannot see why. Most reports of this error suggest that it is reading a HTML tag somewhere ... but I cannot see it.
var oReq = new XMLHttpRequest(); //New request object
oReq.onload = function() {
document.getElementById("myConsole").innerHTML = this.responseText;
myData = JSON.parse(this.responseText);
...
The third line of code dumps the responseText onto my webpage (into a DIV called 'myConsole'). This shows what I believe to be standard JSON code ... and contains no '<' characters.
The second line of code tries to parse the responseText and give the '<' token error.
The php data source looks like this:
$rowCount = 0;
do { $rowCount += 1;
$dbCurrentRow = $resultSet->fetch_assoc();
$seats[$rowCount]['room'] = $dbCurrentRow['Room'];
$seats[$rowCount]['seat'] = $dbCurrentRow['Seat'] * 1;
$seats[$rowCount]['x'] = $dbCurrentRow['x'] * 1;
$seats[$rowCount]['y'] = $dbCurrentRow['y'] * 1;
$seats[$rowCount]['name'] = "Joe Bloggs";
$seats[$rowCount]['adno'] = "01234";
$seats[$rowCount]['ev6'] = true;
$seats[$rowCount]['eal'] = true;
$seats[$rowCount]['dpLast'] = "LS";
$seats[$rowCount]['dpCurrent'] = "WA";
$seats[$rowCount]['dpTarget'] = "TG";
$seats[$rowCount]['ma'] = 2 * 1;
} while ($rowCount < $resultSet->num_rows);
echo json_encode($seats);
and the JSON output is this:
{"1":{"room":"35","seat":1,"x":0,"y":0,"name":"Joe
Bloggs","adno":"01234","ev6":true,"eal":true,"dpLast":"LS","dpCurrent":"WA","dpTarget":"TG","ma":2},"2":{"room":"35","seat":2,"x":30,"y":60,"name":"Joe
Bloggs","adno":"01234","ev6":true,"eal":true,"dpLast":"LS","dpCurrent":"WA","dpTarget":"TG","ma":2},"3":{"room":"35","seat":3,"x":60,"y":0,"name":"Joe
Bloggs","adno":"01234","ev6":true,"eal":true,"dpLast":"LS","dpCurrent":"WA","dpTarget":"TG","ma":2},"4":{"room":"35","seat":4,"x":90,"y":90,"name":"Joe
Bloggs","adno":"01234","ev6":true,"eal":true,"dpLast":"LS","dpCurrent":"WA","dpTarget":"TG","ma":2}}
I do not believe it to be a server timing issue since it 'myConsole' dump precedes the error and works fine. It does not look like the JSON is faulty even with a 2d array. The strange thing is if I take the JSON output and save it as 'testDataSample.php' and link my main page directly to it then the same output works flawlessly.
//oReq.open("get", "testDataSample.php", false); //Text JSON output works fine
oReq.open("get", "getData.php", false); // Live from Server ... '<' error
oReq.send();
Any suggestions as to what is wrong, or how I would track this down would be most welcome.
Thank you.
Thank you raghav710 :-)
The console log showed it ... I had some comments at the top of the dataSource.php file which were being included in the echo.
Writing this to my web page ... they were ignored and invisible ... which means I could not see them, and could not see the difference between the two outputs; parsing the comments JSON caused the choke.
I have removed all of the comments at the top of my datasource.php and it work instantly.
Thank you again.

How do i parse the KairosSDK JSON recognise response in Swift?

For those who don't know what the Kairos SDK is, it's basically a facial recognition api.
When you give it an image, it will tell you who if they can match you with someone in the database.
When i give it an image; the api sends me back this response:
[images: (
{
attributes = {
gender = {
confidence = "80%";
type = F;
};
};
candidates = (
{
"enrollment_timestamp" = 1436883322;
face3rd = "0.988351106643677";
},
{
"enrollment_timestamp" = 1436883214;
hi = "0.94137054681778";
},
{
"enrollment_timestamp" = 1436883132;
hi = "0.94137054681778";
}
);
time = "6.43676";
transaction = {
confidence = "0.988351106643677";
"distance_apart" = "0.046980559825897";
"gallery_name" = test1;
height = 482;
"matching_threshold" = "0.4";
"next_subject" = hi;
"next_subject_confidence" = "0.94137054681778";
"simularity_threshold" = "0.1";
status = success;
subject = face3rd;
topLeftX = 148;
topLeftY = 92;
width = 482;
};
}
)]
What i have done is put three images in the database and have called each of them respectively, face3rd, hi, hi (sorry for the two hi's)
I have been trying to parse the names and the number next to it for soo long, i can get around the 6 second response time.
The reason i have not been able to get the names is because, as you can see, i don't know what to tell Swift to look for. The image name changes depending on who i get back.
I don't know if i've explained my situation, bestly, but if you look at the response. The parts that say:
face3rd = "0.988351106643677";
hi = "0.94137054681778";
hi = "0.94137054681778";
I need the information on both sides of the equal sign.
Thank you for your help and apologise, if reading it was pedantic or you felt like their was a lot of repetion.
Thanks!
Yes, it is poorly formatted JSON that we are returning. We will fix it in an upcoming version of the API (no release date at this time..sorry).
If all you need is the closest match, you can just access the subject variable directly and ignore the candidates array.
Otherwise, you would need to parse the candidates array manually unfortunately. I'm not sure how to do that in Swift.

Taking a screenshot of a page in InDesign Extension Builder

For my current assignment I need to make an extension for Adobe InDesign using Adobe Creative Suit Extension Builder and Flash Builder. I guess this is more of a question for ones that know Extension Builder and InDesign API.
The point of this extension is to load some data and send some data to a server. I need to make a screenshot of a page, then send it in jpg to a server. But, there are no (or at least i couldnt find any) ways to create a bitmap(to cast it on a object seems impossible, because this Objects are just Objects, and not DisplayObjects).
I managed to silently export pages as jpegs, now I'm thinking about loading them and sending but that will require building an AIR app to handle it all, so this will be a bit bulky.
So to sum up the question, how to take a screencapture of all elements on a page in InDesign using CS Ext.Builder?
what is the problem with export to JPG ? You can choose to export the page or the objects themselves.
Here is a snippet I wrote in a recent project. Hope it helps.
public static function getFilePath():String {
var app:com.adobe.indesign.Application = InDesign.app;
var sel:* = app.selection, oldResolution:Number, oldColorSpace:JpegColorSpaceEnum, groupItems:Array = [], i:int = 0, n:int = sel.length;
if (!sel || !n )
{
Alert.show("Pas de selection !", "title", Alert.OK, Sprite(mx.core.Application.application));
return "";
}
for ( i = 0 ; i < n ; i ++ )
{
groupItems [ groupItems.length ] = sel[i];
}
sel = ( sel.length > 1 )? app.activeDocument.groups.add ( sel ) : sel[0] ;
var tempFolder:File = File.createTempDirectory();
AppModel.getInstance().jpgFolder = tempFolder;
var jpgFile:File = new File ();
jpgFile.nativePath = tempFolder.nativePath + "/temp.jpg";
oldResolution = app.jpegExportPreferences.exportResolution;
app.jpegExportPreferences.exportResolution = 72;
oldColorSpace = app.jpegExportPreferences.jpegColorSpace;
app.jpegExportPreferences.jpegColorSpace = JpegColorSpaceEnum.GRAY;
sel.exportFile ( ExportFormat.jpg, jpgFile );
app.jpegExportPreferences.jpegColorSpace = oldColorSpace;
app.jpegExportPreferences.exportResolution = oldResolution;
if ( sel is Group )
{
sel.ungroup();
app.select ( groupItems );
}
return jpgFile.nativePath;
}