Portfolio items created indefinitely from external API. Every time different number

I am trying to make new portfolio item for every json item from external api. I am working on WordPress and placed my code in functions.php of the theme used. When i run my code, it creates portfolio items more than necessary. The items seem to randomly get duplicated even tho i have made validation statement and made sure that each post lug is unique. I want it to stop when the array in json file finishes. Unfortunately I can’t share the api link because it is not supposed to be open-source. It consists of one page. $ model and $ results get correct info. I am new to these WP functions and API thing and got really confused at this point. Hope someone can help me out!:

add_action('wp_ajax_nopriv_get_3dmodels_from_api', 'get_3dmodels_from_api'); add_action('wp_ajax_get_3dmodels_from_api', 'get_3dmodels_from_api');  function get_3dmodels_from_api(){          $  results = wp_remote_retrieve_body(wp_remote_get('<api-url-here>',  array(         'timeout'     => 120,         'httpversion' => '1.1',     ) ) );            $  results = json_decode($  results);     //print_r($  results);           foreach($  results->scenes as $  model) {                  $  model_slug = sanitize_title($  model->name. '-' . $  model->id);                  $  existing_model = get_page_by_path($  model_slug, 'OBJECT', 'portfolio');          if ($  existing_model === null) {              $  inserted_model = wp_insert_post([                 'post_name'=> $  model_slug,                 'post_title'=> $  model_slug,                 'post_type'=> 'portfolio',                 'post_status' => 'publish',             ]);                          if (is_wp_error($  inserted_model)) {                 return false;             }                      $  fillable = [                 'field_605dcef7001bc' => 'name',                 'field_605dcf01001bd' => 'description',                 'field_605dcf09001be' => 'category',                 'field_605dcf13001bf' => 'preview',             ];                          foreach($  fillable as $  key => $  name) {                 $  model_content = $  model->$  name;                                  if ($  name == 'preview') {                     $  model_content = '<img src=' . $  model->$  name . '" alt="">';                 }                                  update_field($  key, $  model_content, $  inserted_model);             }         }  wp_remote_post(admin_url ('admin-ajax.php?action=get_3dmodels_from_api'), [         'blocking' => false,         'sslverify' => false,     ]); } 

Thank you!

Just adding basic token by POST parameter for securing the API. It is safe?

Let’s say I have an address for an API like this:


If accessed, a JSON will appear like this:

[   {     "id":"1",     "name":"John"   },   {     "id":"2",     "name":"Smith"   } ] 

The result defaults will be displaying the entire data if a post has no parameters. If you use post "ID" and the ID parameter value is one of the existing data in the API, it will only display objects from the data selected based on the ID. The API can be accessed by anyone. API needs to be accessed using token parameters to secure the data.

Let’s say I add a token parameter to be able to access data like this:

yourtoken="yourtoken"  if (post_param[token]==yourtoken) {   // Displaying JSON } 

so if you want to open the API, you need to add a token parameter.

Is simple security like this worth using? what vulnerabilities will arise if I use this? is there a better way than this?

How to fix ‘cannot import name get_seomoz_data from api’ error in Python

I tried to get the Alexa ranking for a given website. I used PyPI’s seolib library and installed it in my environment using !pip install seolib –user command. After executing alexa_rank = seolib.get_alexa(‘http://google.com’) code line, I got the following error.

ModuleNotFoundError: No module named 'api' 

Then I installed api module using !pip install api –user command. Then after I got this import error and I don’t have an idea of how to solve this error. Please somebody help on this.

import seolib  alexa_rank = seolib.get_alexa('http://google.com') print(alexa_rank) 
ImportError                               Traceback (most recent call last) <ipython-input-21-b46efa0fce9a> in <module> ----> 1 import seolib       2        3 alexa_rank = seolib.get_alexa('http://google.com')       4 print(alexa_rank)  ~/.local/lib/python3.7/site-packages/seolib/__init__.py in <module>       4        5  ----> 6 from api import get_seomoz_data       7 from api import get_alexa       8 from api import get_semrush  ImportError: cannot import name 'get_seomoz_data' from 'api' (/home/mylap/.local/lib/python3.7/site-packages/api/__init__.py) 

I’m using Python 3.7.3 version on my environment.

is it possible to map all requests to a route under a certain path i.e ‘/api/**’ to a different app in pcf?

As the title suggests, I have a frontend app and a backend api. Each with their own manifest running in pcf in their own containers. They are on the same origin. I want to route all api requests to the backend api, and every other request to the frontend app. This is currently possible via map-route cmd in pcf cli or app manager. For every endpoint I have in my backend api, I map the endpoint to a route ‘api/path1’, ‘api/path2’, ‘api/path3’, ‘api/path4’, ‘api/path5′, api/path6’, ‘api/path7’, ‘api/path8’, ‘api/path9’……………. except the only problem is I have to list every single endpoint I want mapped. Wildcards are not supported..at least I haven’t been able to get them to work. Any ideas?

Laravel api. Как сделать необязательный роут, как в примере

Подскажите, как в Laravel сделать route как тут:

Можно обратиться и без _limit=2 и без ?_page=3&_limit=2

Код, как я сделал:

Route::get('/articles/_page={currentPage?}&_limit={limit?}', "Controller"); 

Пробывал вот так: /articles?_page={currentPage?}&_limit={limit?}.
Да и другими разными способами, не знаю как объявить эту вторую часть как не обяз. параметр

При /api/articles... не обращается.

Best way to make insert data in logs web API. REST or WebSockets

I want to make a centralized log web API, so it will have a large amount of data per seconds. the logs will comming from others WEB API

I was thinking if i make the REST API, all of the POST made need to return an answer and maybe can overload the server with so much request.

then I think in webSockets, establish a communication with the API that made the logs and only send data without necessary responses but I don’t know how reliable are that.

So in this case, what method would be fastest and more reliable? Sorry if my english isn’t good 🙁


AutoFill and ‘Payment Request API’ behavior in chrome

According to this guidance in Chrome Help

Chrome has 2 mechanisms that support saving the payment methods for the browser’s user: – Autofill and the Payment Request API
My Questions

  • what are the difference between them from user experience?
  • When using basic card (credit or debit card) what is the card number stored for continues use, is it stored in some chrome data repository where all the passwords to enter websites is stored?

The notification work just fine when sent from the firebase console, but don’t work when sent from the API. Even when the result displays a success: [on hold]

The notification work just fine when sent from the firebase console, but don’t work when sent from the API. Even when the result displays a success:


APÍ django-storages dropbox erro url pattern

Eu estou utilizando a seguinte API: https://django-storages.readthedocs.io/en/latest/backends/dropbox.html

Eu tenho exatamente tudo configurado, desde a lib instalada até as configurações do settings.py.

A lib ‘storages’ no INSTALLED_APPS e as três variáveis de conexão com o dropbox:

DEFAULT_FILE_STORAGE = ‘storages.backends.dropbox.DropBoxStorage’ DROPBOX_OAUTH2_TOKEN = ‘meu_token’ DROPBOX_ROOT_PATH = ‘/media/’

Eu quero que os campos FileField e ImageField façam upload de uma imagem ou arquivo e este seja salvo na pasta /media/ do projeto e do dropbox, mantendo a imagem em produção, tendo a App criada e configurada para ser app_folder.

Se eu retirar as três variáveis de configuração do dropbox e tentar modificar ou adicionar uma imagem pelo django admin é possível, porém, quando retorno as variáveis e tento novamente, aparece o seguinte erro:

ValidationError at /admin/catalog/product/6/change/ 

‘C:/media/products/cortina-city.jpg’ did not match pattern ‘(/(.|[\r\n])|id:.)|(rev:[0-9a-f]{9,})|(ns:[0-9]+(/.*)?)’

Dá erro também no dropbox.py da lib:

C:\Users\evert\Desktop\Synth\SynthDev\myenv\lib\site-packages\storages\backends\dropbox.py in exists         return bool(self.client.files_get_metadata(self._full_path(name))) ... C:\Users\evert\Desktop\Synth\SynthDev\myenv\lib\site-packages\dropbox\base.py in files_get_metadata                                include_property_groups) ... C:\Users\evert\Desktop\Synth\SynthDev\myenv\lib\site-packages\dropbox\files.py in __init__         self.path = path ... C:\Users\evert\Desktop\Synth\SynthDev\myenv\lib\site-packages\dropbox\files.py in path     val = self._path_validator.validate(val) ... C:\Users\evert\Desktop\Synth\SynthDev\myenv\lib\site-packages\dropbox\stone_validators.py in validate                               % (val, self.pattern))  

Eu entendo que não está identificando o padrão do get da url. Imagino que o C: não deve ir junto na string e está indo, ou seja, ‘C:/media/products/..”.

Como resolver isso?