Bitrix 1C has an option: Google Sitemap.
How to create an agent, which will create this sitemap automatically? I mean, what I need to write, some function...
1) create function that will be run by agent, for example 'agentSitemapGenerator',
in /bitrix/php_interface/init.php
function agentSitemapGenerator()
{
// implement sitemap generation call
// function must return its name
return "agentSitemapGenerator();";
}
2) implement sitemap generation call in your function.
I found this example
//подключение модуля поиска
if(CModule::IncludeModule('search'))
{
//В этом массиве будут передаваться данные "прогресса". Он же послужит индикатором окончания исполнения.
$NS=Array();
//Задаем максимальную длительность одной итерации равной "бесконечности".
$sm_max_execution_time = 0;
//Это максимальное количество ссылок обрабатываемых за один шаг.
//Установка слишком большого значения приведет к значительным потерям производительности.
$sm_record_limit = 5000;
do {
$cSiteMap = new CSiteMap;
//Выполняем итерацию создания,
$NS = $cSiteMap->Create("ru", array($sm_max_execution_time, $sm_record_limit), $NS);
//Пока карта сайта не будет создана.
} while(is_array($NS));
}
code from: http://dev.1c-bitrix.ru/community/blogs/oracle/254.php
description of CSiteMap::Create in official documentation https://dev.1c-bitrix.ru/api_help/search/classes/csitemap/create.php
3) create agent in control panel
Related
I am trying to add this code snippet to the wed apis demo project but I tried and failed and there isnt much documentation on how to do it.
var os = require("os");
var bytesAvailable = os.totalmem(); // returns number in bytes
// 1 mb = 1048576 bytes
console.log("Total memory available MB :" + (bytesAvailable/1048576) );
it needs to have a type script file and a javascript file according to the implamentation with the create excel.js demo but im not sure how to go about that process.
FYI everyone looking at this, the developer made a decent tutorial for this but lets just go with im the type of developer who is kinda dumb but competent.
So Basically your gonna want to create a type script file using the index.ts file as a template
once you have a type script file place your custom JS in the onHostRead() part of the script
build it
this will create the js file and make it look similar to the other example files.
create a controller for your custom js like hosthook.cs, this is called the mainfunction in the api demo
add front facing logic to your software. ....so still testing idk If i got it right just yet
This did not work in visual studio code , I used visual studio 2022
dont install the type script nuget package visual studio recommends , its not in the documentation, will break build.
sometimes the people capable are too busy to help so dive deep in the code and get good (talking to myself here)
ipController.cs
using ElectronNET.API;
using ElectronNET.API.Entities;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
namespace ElectronNET_API_Demos.Controllers
{
public class IPController : Controller
{
public IActionResult Index()
{
if (HybridSupport.IsElectronActive)
{
Electron.IpcMain.On("start-hoosthook", async (args) =>
{
var mainWindow = Electron.WindowManager.BrowserWindows.First();
var options = new OpenDialogOptions
{
Properties = new OpenDialogProperty[]
{
OpenDialogProperty.openDirectory
}
};
var folderPath = await Electron.Dialog.ShowOpenDialogAsync(mainWindow, options);
var resultFromTypeScript = await Electron.HostHook.CallAsync<string>("get-ip-address", folderPath);
Electron.IpcMain.Send(mainWindow, "ip-address-found", resultFromTypeScript);
});
}
return View();
}
}
}
ipAddress.ts
// #ts-ignore
import * as Electron from "electron";
import { Connector } from "./connector";
import { IPAddress } from "./ipAddress";
export class HookService extends Connector {
constructor(socket: SocketIO.Socket, public app: Electron.App) {
super(socket, app);
}
onHostReady(): void {
// execute your own JavaScript Host logic here
var os = require("os");
var result = console.log(os.networkInterfaces);
return result;
}
}
ipAddress.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HookService = void 0;
const connector_1 = require("./connector");
class HookService extends connector_1.Connector {
constructor(socket, app) {
super(socket, app);
this.app = app;
}
onHostReady() {
// execute your own JavaScript Host logic here
var os = require("os");
var result = console.log(os.networkInterfaces);
return result;
}
}
exports.HookService = HookService;
//# sourceMappingURL=ipAddress.js.map
I'm getting an error using Laravel PayPal billing agreement. I received HTTP response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/billing-agreements/. I'm
getting this error once I try to complete the agreement process.
$id = my_created_plan_id
protected function agreement($id)
{
$agreement = new Agreement();
$agreement->setName('Base Agreement')->setDescription('Basic Agreement')
// ->setStartDate(date("Y-m-d").'T9:45:04Z'); ->setStartDate('2021-07-05T9:45:04Z');
$agreement->setPlan($this->Plan($id));
$agreement->setPayer($this->payer());
$agreement->setShippingAddress($this->shippingAddress());
$agreement = $agreement->create($this->apiContext);
return $agreement->getApprovalLink();
}
protected function Plan($id)
{
$plan = new Plan();
$plan->setId($id);
return $plan;
}
protected function payer()
{
$payer = new Payer();
$payer->setPaymentMethod('paypal');
return $payer;
}
protected function shippingAddress()
{
$shippingAddress = new ShippingAddress();
$shippingAddress->setLine1('111 First Street')
->setCity('Saratoga')
->setState('CA')
->setPostalCode('95070')
->setCountryCode('US');
return $shippingAddress;
}
You are using a deprecated SDK that does not support the current version of PayPal Subscriptions, for which there is no SDK.
Change your integration to not use that old SDK. The new Subscribe button itself is JavaScript. Use direct HTTPS calls with curl or similar when you need to call an API to create Products and Plans or administer Subscriptions.
(You can also do so in your account's web interface, rather than via API)
Sandbox: https://www.sandbox.paypal.com/billing/
Live: https://www.paypal.com/billing/
protected function agreement($id)
{
$agreement = new Agreement();
$agreement->setName('Base Agreement')->setDescription('Basic Agreement')
// ->setStartDate(date("Y-m-d").'T9:45:04Z'); ->setStartDate('2021-07-05T9:45:04Z');
//Replace above line with below line
//->setStartDate(gmdate("Y-m-d\TH:i:s\Z", time()+60));
$agreement->setPlan($this->Plan($id));
$agreement->setPayer($this->payer());
$agreement->setShippingAddress($this->shippingAddress());
$agreement = $agreement->create($this->apiContext);
return $agreement->getApprovalLink();
}
You cannot comment on the start date of the agreement.
you must provide the start date of agreement and the error occurred due to this issue.
I am trying to create a simple Xamarin forms app which allows the user to browse for or take a photo and have azure cognitive services tag the photo using a custom vision model.
I am unable to get the client to successfully authenticate or find a resource per the error message in the exception produced by the VisionServiceClient. Am I missing something? What would be the correct values to use for the arguments to VisionServiceClient?
All keys have been removed from the below images, they are populated.
Exception thrown in VS2017:
'Microsoft.ProjectOxford.Vision.ClientException' in System.Private.CoreLib.dll
Call to VisionServiceClient:
private const string endpoint = #"https://eastus2.api.cognitive.microsoft.com/vision/prediction/v1.0";
private const string key = "";
VisionServiceClient visionClient = new VisionServiceClient(key, endpoint);
VisualFeature[] features = { VisualFeature.Tags, VisualFeature.Categories, VisualFeature.Description };
try
{
AnalysisResult temp = await visionClient.AnalyzeImageAsync(imageStream,
features.ToList(), null);
return temp;
}
catch(Exception ex)
{
return null;
}
VS Exception Error:
Azure Portal for cognitive services:
Custom Vision Portal:
It looks like you're confusing the Computer Vision and the Custom Vision APIs. You are attempting to use the client SDK for the former using the API key of the latter.
For .NET languages, you'll want the Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction NuGet package.
Your code will end up looking something like this:
ICustomVisionPredictionClient client = new CustomVisionPredictionClient()
{
ApiKey = PredictionKey,
Endpoint = "https://southcentralus.api.cognitive.microsoft.com"
};
ImagePrediction prediction = await client.PredictImageAsync(ProjectId, stream, IterationId);
Thank you to cthrash for the extended help and talking with me in chat. Using his post along with a little troubleshooting I have figured out what works for me. The code is super clunky but it was just to test and make sure I'm able to do this. To answer the question:
Nuget packages and classes
Using cthrash's post I was able to get both the training and prediction nuget packages installed, which are the correct packages for this particular application. I needed the following classes:
Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction
Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.Models
Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training
Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training.Models
Endpoint Root
Following some of the steps Here I determined that the endpoint URL's only need to be the root, not the full URL provided in the Custom Vision Portal. For instance,
https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Prediction/
Was changed to
https://southcentralus.api.cognitive.microsoft.com
I used both the key and endpoint from the Custom Vision Portal and making that change I was able to use both a training and prediction client to pull the projects and iterations.
Getting Project Id
In order to use CustomVisionPredictionClient.PredictImageAsync you need a Guid for the project id and an iteration id if a default iteration is not set in the portal.
I tested two ways to get the project id,
Using project id string from portal
Grab the project id string from the portal under the project settings.
For the first argument to PredictImageAsync pass
Guid.Parse(projectId)
Using the training client
Create a new CustomVisionTrainingClient
To get a list of <Project> use
TrainingClient.GetProjects().ToList()
In my case I only had a single project so I would just need the first element.
Guid projectId = projects[0].Id
Getting Iteration Id
To get the iteration id of a project you need the CustomVisionTrainingClient.
Create the client
To get a list of <Iteration> use
client.GetIterations(projectId).ToList()
In my case I had only a single iteration so I just need the first element.
Guid iterationId = iterations[0].Id
I am now able to use my model to classify images. In the code below, fileStream is the image stream passed to the model.
public async Task<string> Predict(Stream fileStream)
{
string projectId = "";
//string trainingEndpoint = "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.2/Training/";
string trainingEndpoint = "https://southcentralus.api.cognitive.microsoft.com/";
string trainingKey = "";
//string predictionEndpoint = "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Prediction/";
string predictionEndpoint = "https://southcentralus.api.cognitive.microsoft.com";
string predictionKey = "";
CustomVisionTrainingClient trainingClient = new CustomVisionTrainingClient
{
ApiKey = trainingKey,
Endpoint = trainingEndpoint
};
List<Project> projects = new List<Project>();
try
{
projects = trainingClient.GetProjects().ToList();
}
catch(Exception ex)
{
Debug.WriteLine("Unable to get projects:\n\n" + ex.Message);
return "Unable to obtain projects.";
}
Guid ProjectId = Guid.Empty;
if(projects.Count > 0)
{
ProjectId = projects[0].Id;
}
if (ProjectId == Guid.Empty)
{
Debug.WriteLine("Unable to obtain project ID");
return "Unable to obtain project id.";
}
List<Iteration> iterations = new List<Iteration>();
try
{
iterations = trainingClient.GetIterations(ProjectId).ToList();
}
catch(Exception ex)
{
Debug.WriteLine("Unable to obtain iterations.");
return "Unable to obtain iterations.";
}
foreach(Iteration itr in iterations)
{
Debug.WriteLine(itr.Name + "\t" + itr.Id + "\n");
}
Guid iteration = Guid.Empty;
if(iterations.Count > 0)
{
iteration = iterations[0].Id;
}
if(iteration == Guid.Empty)
{
Debug.WriteLine("Unable to obtain project iteration.");
return "Unable to obtain project iteration";
}
CustomVisionPredictionClient predictionClient = new CustomVisionPredictionClient
{
ApiKey = predictionKey,
Endpoint = predictionEndpoint
};
var result = await predictionClient.PredictImageAsync(Guid.Parse(projectId), fileStream, iteration);
string resultStr = string.Empty;
foreach(PredictionModel pred in result.Predictions)
{
if(pred.Probability >= 0.85)
resultStr += pred.TagName + " ";
}
return resultStr;
}
I have this code for my Google Chrome extension which solves reCAPTCHA automatically.
"use strict"
var sid = setInterval(function () {
if (window.location.href.match(/https:\/\/www.google.com\/recaptcha\/api\d\/anchor/) && $("#recaptcha-anchor div.recaptcha-checkbox-checkmark").length
&& $("#recaptcha-anchor div.recaptcha-checkbox-checkmark").is(':visible') && isScrolledIntoView($("#recaptcha-anchor div.recaptcha-checkbox-checkmark").get(0)))
{
var execute = true;
if (sessionStorage.getItem('accesstime'))
{
if (new Date().getTime() - sessionStorage.getItem('accesstime') < 7000)
{
execute = false;
}
}
if (execute)
{
$("#recaptcha-anchor div.recaptcha-checkbox-checkmark").click();
sessionStorage.setItem('accesstime', new Date().getTime());
}
clearInterval(sid);
}
}, 500);
My question is...
From the above code. How do I get the data-sitekey and page url?
I know this is old, but for people in same situation:
Use your account of Google(Gmail)
go to this link https://www.google.com/recaptcha/intro/v3beta.html
- use the button Myrecaptcha
- register a new site
- give a label "my site label"
- Choose the type of reCAPTCHA
- enter the domain for you want use the captcha
- check the Accept the reCAPTCHA Terms of Service.
- check or not the send alerts to owners
- Click "register"
That´s all when finish you will see intructions and your data-sitekey.
I have a spreadsheet that contains links created after a form entry. I'd like to call the external API of a link shortening service (not google's link shorten-er) to take the link created in a given cell, shorten it, return the value and have Google Apps Script insert that shortened link into a new cell.
Is this possible? Specifically, can I use jQuery's AJAX methods? Where should I start.
By checking the internet, I found this stackExchange question, you can try to follow the solution in this post. What you need here is URL shortener API under the resources in the script editor (Tools > Script editor) select the Advanced Google Services and activate the UrlShortener.
Here is the sample code that you need to use.
function onOpen() {
SpreadsheetApp.getUi()
.createMenu("Shorten")
.addItem("Go !!","rangeShort")
.addToUi()
}
function rangeShort() {
var range = SpreadsheetApp.getActiveRange(), data = range.getValues();
var output = [];
for(var i = 0, iLen = data.length; i < iLen; i++) {
var url = UrlShortener.Url.insert({longUrl: data[i][0]});
output.push([url.id]);
}
range.offset(0,1).setValues(output);
}
For more information, explanation and some sample pictures, just check the link above.