Tuesday, 31 March 2020

Error: No module named flask in python

Error: No Module named flask, for python application

(venv) C:\Python\sandbox>py -m flask run
C:\Python\sandbox\venv\Scripts\python.exe: No module named flask

When you try to run the python application using flask you may get the above error: 
root cause: There is no flask installation found in the directory you are currently trying to access the application.
Solution:
When you over come the above error first install flask using below command:
py -m pip install Flask

Then try: py -m flask run 

Now your system will recognize your command and run the flask application.

Sunday, 29 March 2020

Mat Autocomplete list in Angular 7

How to create an Autocomplete list in Angular 7:


Here I am going to show how to get and display an autocomplete list of contents based on the input given by user.

Create a Form with Input and Mat Autocomplete in the .html file:

<form [formGroup]="serviceForm" (ngSubmit)="addService()" data-automation-attribute="form-op-service">
    <mat-grid-list cols="12" rowHeight="65px">
       <mat-grid-tile [colspan]="9">
          <mat-form-field *ngIf="searchType == '1'" class="full-width" appearance="outline">
             <mat-label>Service Name</mat-label>
             <input                  
                    cdk-focus-initial
                    type="text"
                    placeholder="Service Name"
                    matInput
                    [matAutocomplete]="auto"
                    formControlName="serviceName"
                    [(ngModel)]="serviceName"
                    (input)="getserviceOnSearch()"
                    data-automation-attribute="text-service-name" />
                  <mat-autocomplete #auto="matAutocomplete" (optionSelected)="serviceOnSelect($event.option.value)">
                    <mat-option *ngFor="let service of filteredOptions | async"
                      [value]="service.serviceName">
                      {{ service.serviceName }}
                    </mat-option>
                  </mat-autocomplete>
                </mat-form-field>
</mat-grid-tile>
</mat-grid-list>
</Form>

Explanation:

Main code in the input field:
matAutocomplete set as auto.
input: to get the input entered by the user
under mat-option set the filtered option to get the latest list based on the user key.
Once the user enter the key then using ngModel it will be captured in the method getserviceOnSearch(). The functionality of this method is given below in detail.


Add below code into .TS file:

serviceName: string = "";

//This method is used to filter using the user key and return a customized list
searchedText: string = "";
  getserviceOnSearch() {
    let splitText: any;
    if (
      this.serviceName &&
      //this.searchedText != this.serviceName &&
      (this.serviceName.length == 3 ||
        this.serviceName.length == 5 ||
        this.serviceName.length > 7)
    ) {
      this.searchedText = this.serviceName;

      this.http.get<any>('https://api.io/')
        .getResource(
          "billing-masters/unit-wise-services?searchKey=" + this.serviceName
        )
        .subscribe(res => {
          if (res) {
            this.services = res;
            this.filteredOptions = this.serviceControl.valueChanges.pipe(
              startWith(""),
              map(value => this._filter(value))
            );
          }
        });
    } else if (this.serviceName.length <= 2) {
      this.filteredOptions = new Observable<string[]>();
    }
  }

private _filter(value: string): string[] {
    const filterValue = value.toLowerCase();
    return this.services.filter(option =>
      option.serviceName.toLowerCase().includes(filterValue)
    );
  }

The above code is very simple just need to add this method and the list will populate based on the key entered. If you want to populate the complete list during the application start then add the below code in OnInit method to load the complete API response into the list.

ngOnInit() {
this.http.get<any>('https://api.io/')
        .getResource(
          "billing-masters/unit-wise-services?searchKey=" + this.serviceName=""
        )
        .subscribe(res => {
          if (res) {
            this.services = res;
            this.filteredOptions.next(this.services.slice());
          }
        });
    } else if (this.serviceName.length <= 2) {
      this.filteredOptions = new Observable<string[]>();
    }
}

The above code will add the complete response into the list which will show user all the options that are available and once the key is entered it will filter the options and refresh the list based on the key.

Cannot read property 'nativeElement' of undefined angular 7

This error is one of the common error which we get when there is a mismatch in the typescript and html in Angular 7.

To avoid this error kindly notice the below code for reference

In example.component.ts        
@ViewChild("nameField")nameField:ElementRef;

In example.component.html
<input                      
             cdk-focus-initial 
             #nameField
             type="text" 
             placeholder="Service Name" 
             matInput
             [matAutocomplete]="auto" 
             formControlName="serviceName" 
             [(ngModel)]="serviceName"
             (input)="getserviceOnSearch()" 
  data-automation-attribute="text-service-name" />

COVID-19 - Information about corona, symptoms and how it spread

About COVID-19:

COVID-19 as Corona is a virus which now can attack humans. this virus has been infecting animals for over years which have now evolved or have been evolved to infect humans. This virus is also like similar to HIV which start attacking the immunity system first and once it has weaken the system then spread to lungs and give server damage to lunch. This is a deadly virus and a well developed human will get infected and will be developing in the host for over 1 week to 14 days. During these period your body before start recognizing the virus will get developed and it will start spreading to your lungs.

Symptoms:

During the first attack of this virus, you will get sore throat (server). And this is the first symptom which is also common when we get cold.
1. Tiredness
2. Sore throat and irritation
3. Cough
4. Fever
5. difficult in breathing (once it attack your lungs)

How it spread?

The virus can spread through below process:
1. Hand to hand contact
2. Victim sneeze
3. Hope the virus can be alive for 8 days outside
4. Even if there is a heavy moist in air the virus can be alive and spread through air

How to avoid this?

Currently we have to stay in closed place, not to roam in open space also avoid going to places where the Corona positive victims have been spotted.

Expense Handler Application with advance technologies

Budget Planner  One of the application developed with Ionic 4 and Python-Flask.  Ionic 4 code:  https://github.com/logeshbuiltin/Expense...