Importing GeoPt data with the Google AppEngine BulkLoader YAML - google-cloud-datastore

I am uploading data from a csv file with a GeoPt column in it. I have the GeoPt column data in quotes like this: SomeData,"54.321,-123.456",MoreData
My bulkloader.yaml file has an entry like this:
- property: location
external_name: LOCATION
# Type: GeoPt Stats: 1 properties of this type in this kind.
When I do the upload and go to the DataStore viewer I see the location has been uploaded as a string instead of a GeoPt. I'm not sure what the proper way to import this would be. Perhaps it requires an import_transform?

Create a uploadutil.py file and add this method in it:
def geo_converter(geo_str):
if geo_str:
lat, lng = geo_str.split(',')
return db.GeoPt(lat=float(lat), lon=float(lng))
return None
Then add this in bulkloader.yaml:
Add import for uploadutil:
- import: uploadutil
And add property:
- property: location
external_name: LOCATION
import_transform: uploadutil.geo_converter

If you get NameError global name 'db' is not defined while uploading data, add line
from google.appengine.ext import db
to file uploadutil.py

Related

Need help for mapping dynamic data with nginx

i have a content like this ( can be stored in a text file or database or etc):
[
{
"site_slug": "/site1",
"site_url": "http://site1.com"
}
]
i want nginx can read the data and map the location path with key: "site_slug" and redirect to "site_url"
is it possible? could you give me some keywords for googling?

How to pass a parameter from the Jupyter backend to a frontend extension

I currently have a value that is stored as an environment variable the environment where a jupyter server is running. I would like to somehow pass that value to a frontend extension. It does not have to read the environment variable in real time, I am fine with just using the value of the variable at startup. Is there a canonical way to pass parameters a frontend extension on startup? Would appreciate an examples of both setting the parameter from the backend and accessing it from the frontend.
[update]
I have posted a solution that works for nbextentions, but I can't seem to find the equivalent pattern for labextensions (typescript), any help there would be much appreciated.
I was able to do this by adding the following code to my jupter_notebook_config.py
from notebook.services.config import ConfigManager
cm = ConfigManager()
cm.update('notebook', {'variable_being_set': value})
Then I had the parameters defined in my extension in my main.js
// define default values for config parameters
var params = {
variable_being_set : 'default'
};
// to be called once config is loaded, this updates default config vals
// with the ones specified by the server's config file
var update_params = function() {
var config = Jupyter.notebook.config;
for (var key in params) {
if (config.data.hasOwnProperty(key) ){
params[key] = config.data[key];
}
}
};
I also have the parameters declared in my main.yaml
Parameters:
- name: variable_being_set
description: ...
input_type: text
default: `default_value`
This took some trial and error to find out because there is very little documentation on the ConfigManager class and none of it has an end-to-end example.

Add Color Scheme JSON list to Scss file in Angular 8 Environment

I'm building a Web based project with Angular 8. At the starting of the Application, I need to retrieve a list of predefined colour scheme defined in a JSON file and I have to add them dynamically to the Application. The colour scheme JSON looks like as below:
{
"bar": "#FFFFFF",
"text_small": "#FFFFFF",
"text_nav_header": "#FFFFFF"
............ ...........
........... ...........
}
I have gone through few links as below but somehow I'm missing the point to import this JSON to the SCSS processing.
https://scotch.io/tutorials/angular-shortcut-to-importing-styles-files-in-components
https://medium.com/#dmitriy.borodiy/easy-color-theming-with-scss-bc38fd5734d1
https://css-tricks.com/making-sass-talk-to-javascript-with-json/
https://www.viget.com/articles/sharing-data-between-sass-and-javascript-with-json/
Please refer to the below link that I want to achieve with SCSS
Sample code with gist on SassMeister.
Can somebody through some light that what I'm missing here? Also, I'm not an expect in CSS but can understand the basic use of the CSS and media queries.
Thanks in Advance
Are you sure that these color variables have to be inside a json file?
If the values are generated: then change the output format to a scss file.
If the values are defined once (or not very often) : copy/paste them to a scss file.
Here are the steps that I work out with the Angular and backend script to achieve it.
After Angular App is started. I downloaded the JSON in the background and written a file with few changes as mentioned below.
Convert the JSON to JSONString.
Add a string ':root' before the JSONString.
In Python:
data = ":root %s" % jsonString
In PHP:
$data = ":root ". $jsonString;
Replace few character in the string as below:
In Python
data = data.replace('\"', '')
data = data.replace(',', ';')
In PHP:
$data = str_replace('\"', '', $data);
$data = str_replace(',', ';', $data);
Write a file to the src folder of the Angular project.
In Python:
f = open("src/themes.scss", "w+")
f.write(data)
f.close()
In PHP:
$fp = fopen('src/themes.scss', 'w');
fwrite($fp, $data);
fclose($fp);
Import the filename.scss in your styles.css file of your Angular project.
#import "themes.scss";
Thus how I have generated the dynamic scss file with a JSON of color codes. It look weird but yes, it works like a charm.
Note: It works in production environment of Angular as well

External environment variable as array

How to set external environment variable as array?
If I have environment variable
SYMFONY__NSQLOOKUPD__HOSTS=["localhost:4161"]
and in config.yml:
socloz_nsq:
lookupd_hosts: %nsqlookupd.hosts%
Then I got an error:
Invalid type for path "socloz_nsq.lookupd_hosts". Expected array, but got string
I've found solution. Here it is:
in config.yml add to the imports section:
imports:
- { resource: parameters.php }
then create parameters.php file at the same directory where config.yml exists, and look at the following example:
<?php
$nsqlookupdhosts = getenv('SYMFONY__NSQLOOKUPD__HOSTS');
$nsqdhosts = getenv('SYMFONY__NSQD__HOSTS');
$container->setParameter('nsqlookupd.hosts.parsed', explode(',', $nsqlookupdhosts));
$container->setParameter('nsqd.hosts.parsed', explode(',', $nsqdhosts));
use comma as delimiter in environment variable (you are not restricted to comma, use any)
SYMFONY__NSQLOOKUPD__HOSTS=localhost:4161,some.server:2222
You can use a built-in "json" environment variable processor to decode a JSON string into an array:
SYMFONY__NSQLOOKUPD__HOSTS='["localhost:4161"]'
$nsqlookupdhosts: '%env(json:SYMFONY__NSQLOOKUPD__HOSTS)%'

Convert Bundle:Controller:Filename to actual file path

Is there a way to convert Symfony filename notation Bundle:Controller:Filename to a real file path /var/www/whatever/src/Bundle/Resources/views/Controller/Filename?
Tak a look at this question: Resolve local file path from Twig template name . Accepted answer says:
"If you want to retrieve path from a controller you can use this code:
$parser = $this->container->get('templating.name_parser');
$locator = $this->container->get('templating.locator');
$path = $locator->locate($parser->parse('AcmeProjectBundle::home.html.twig'));
For more info take a look at code of:
Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser::parse
Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator::locate
"

Resources