Saturday, October 9, 2021

Recent Questions - Stack Overflow

Recent Questions - Stack Overflow

Recent Questions - Stack Overflow


how to print large amount of data in beautiful soup

Posted: 09 Oct 2021 08:33 AM PDT

I am trying to print large amount of data I try to print title,price,descriptionand table but these code will print data but it will give me the few data is any method they will give all the data that I am looking forward

import requests  from bs4 import BeautifulSoup  import pandas as pd  from urllib.parse import urljoin  base_url='https://www.amazon.com'    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36','session':'141-2320098-4829807'}  r = requests.get('https://www.amazon.com/s?rh=n%3A1069242&fs=true&ref=lp_1069242_sar', headers = headers)  soup = BeautifulSoup(r.content, 'lxml')  for link in soup.find_all('a',class_="a-link-normal s-underline-text s-underline-link-text a-text-normal",href=True):      p=link['href']      l=urljoin(base_url,p)      data.append(l)        for link in data:          r =requests.get(link,headers=headers)          soup=BeautifulSoup(r.content, 'html.parser')          try:              title=soup.find('span',id='productTitle').text          except:              title=''          try:              price=soup.find('span',id='priceblock_ourprice').text          except:              price=''          des=soup.find('div',id='productDescription_feature_div').find_all('p')               try:              for tr in soup.find('table', id='productDetails_techSpec_section_1').find_all('tr') :                  res = "".join(tr.text.strip().split("\n\n\n\u200e"))                            except:              continue            print(title,price,des,res)  

Apply animation on image in flutter

Posted: 09 Oct 2021 08:33 AM PDT

I want help to apply this animation using flutter enter image description here

thanks in advance

Managing composable functions with Jetpack Compose Navigation

Posted: 09 Oct 2021 08:33 AM PDT

I have few @Composable functions that contains UI. I've also set up BottomNavigation with Scaffold, which works just fine. Now the problem is, I can't figure out how would I navigate to a different screen/composable in fullscreen(with full width and height). Look at below code:

@Composable  fun MainScreen() {      navController = rememberNavController()        Scaffold(          topBar = { TopBar() },          floatingActionButton = {              if(currentRoute(navController) != "more")                  FAB()          },          bottomBar = { BottomBar(navController) },          content = { innerPadding ->              Box(modifier = Modifier.padding(innerPadding)) {                  NavigateScreens(navController = navController)              }          },      )  }  

This code works fine but as you can see my NavigateScreens is in the Scaffold's content so everything renders between TopBar and BottomNavigation. How would I structure this so I can also open composable in fullscreen?

How to check if a Azure Cosmos DB client connection is successful with Java SDK?

Posted: 09 Oct 2021 08:33 AM PDT

Is there a way/method to check if my Cosmos DB client is successfully connected to the Azure Cosmos DB using the Java SDK?

Ansible role dependency handling for collections

Posted: 09 Oct 2021 08:33 AM PDT

When creating an ansible role you can specify the dependencies in meta/main.yml as follows

dependencies:  - role: papanito.xxx  

How I do this, if papanito.xxx was converted into a collection? Or let's phrase it otherwise: How to I tell my role, that it depends on a module/role from a collection?

ExtJS - Where to put new plugins?

Posted: 09 Oct 2021 08:32 AM PDT

In ExtJS 6.2 modern application directory structure, where should I put new plugins?

In ExJS the PagingToolbar plugin has this definition Ext.grid.plugin.PagingToolbar, if I create a Grid plugin should I put it in APP/grid/plugin/MyPlugin?

Also, do I have to import the plugin into the system somehow before use?

how to print all prime numbers from 1 to 100 in java

Posted: 09 Oct 2021 08:33 AM PDT

I want to print all the prime numbers from 1 to 100 and I have written this code and i don't know what is going wrong with this. my code:

package com.company;    public class sum_of_the_prime_no {      public static void main(String[] args) {            int [] a=new int [100];              for(int i=1;i<=100;i++)          {              for(int j=1;j<=100;j++)              {                  if(i%j==0)                  {                      int k=0;                        a[k]=i;                        k++;                  }              }          }          for(int i=0;i<=30;i++)          {              System.out.println(a[i]);          }          }  }  

and output is:

100  0  0  0  0  0.....  

plese help me , i am beginner in java.

Example usage FirstOrDefaultDynamic with VB.NET

Posted: 09 Oct 2021 08:31 AM PDT

I'm using VB in a project, together with EF.PLUS https://entityframework-plus.net/

I want to use FirstOrDefaultDynamic, but I didn't found any example for usage in VB - all examples are in C#

Specifically I have an array of array of strings, and I want to find element in it

dim a = {      {"a", "a1"},      {"b", "b1"},      {"c", "c1"}  }    dim elem = a.FirstOrDefaultDynamic("x(0) = y", new with {y="a"})  

But I get error on evaluating the expression.

FirstOrDefaultDynamic accepts only string expression as parameter, not predicate (function).

The C# example is

var list = ctx.WhereDynamic(x => "x > 2").ToList();  

but it still accepts a function returning an string expression which is to be evaluated Any idea on the VB syntax?

Thank you

Easiest way to geoblock users from website?

Posted: 09 Oct 2021 08:31 AM PDT

What is the easiest way to geoblock users from e.g. China / Iran from accessing my website? FYI its Django + NGINX on Linode. I've read about MaxMind tables but seems complex and only seems works with NGINX Plus which is like $2500 / year. Also Cloudflare, probably easy but potentially only for enterprise subscriptions. Is using built in Django (https://docs.djangoproject.com/en/3.2/ref/contrib/gis/geoip2/) the best option? Do I move to AWS and see if they have something? If anyone has been in this situation it would be great to hear what worked for you, thanks.

PS; it's more distribution compliance than stopping DDoS etc, so blocking the majority of average users is enough.

WAP in javascript to insert new line in each and every whitespace occurence

Posted: 09 Oct 2021 08:33 AM PDT

// My code in javascript

const data=['City Country State']; const output=data[0].split(' ').join('\n'); console.log(output)

My Output is City\nCountry\nState

My Desired output is

City\nCountry\nState  

Why does the last line in cmd powershell -command error

Posted: 09 Oct 2021 08:31 AM PDT

'C:\Users\kevin>powershell -Command "$Url = 'http://shared4.info/psequotes/files/2021/stockQuotes_$CurrentDate.csv'"

C:\Users\kevin>powershell -Command "$Path = 'C:\Users\kevin\Desktop\stockQuotes_$CurrentDate.csv'"

C:\Users\kevin>powershell -Command "$WebClient = New-Object System.Net.WebClient"

C:\Users\kevin>powershell -Command "$WebClient.DownloadFile($url, $path)" You cannot call a method on a null-valued expression. At line:1 char:1

  • $WebClient.DownloadFile($url, $path)
  •   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : InvokeMethodOnNull'  

I need co occurrence dataframe from character in python

Posted: 09 Oct 2021 08:32 AM PDT

import pandas as pd  corpus = pd.DataFrame([[1, 'A B C A D B A'], [2, 'B A B B C B A']], columns=['id', 'sequence'])  corpus  

Expected Output

    A B C D  1   3 2 1 1  2   2 4 1 0  

I have a data frame look like above I need to count co occurrence of each character

Error in Visual-Studio "No module named 'IPython'"

Posted: 09 Oct 2021 08:32 AM PDT

When I run the script:

import matplotlib.pyplot as plt  import numpy as np  import pandas as pd  from IPython.core.debugger import set_trace  

But the following error is displayed. Displayed Error

I installed Ipython in the terminal. The version I have is 7.22

Version of Ipython Installed

How can I fix it?

SQL - Reference a column value in the same query context

Posted: 09 Oct 2021 08:33 AM PDT

I need to know if there's any way I can reference a column value in the same query context.

In this example I'm defining "amount" value on the second nested select and trying to access it on the first nested select.

I'm getting Reference 'amount' not supported (forward reference in item list)

I know if I define "amount" first on the columns list it works but it will change the order, affecting target tables.

select      col_1,      col_2,      (select if(amount >= 0, 'debit', 'credit')),      col_3,      (select json_value((select json from table), '$.key.val')) as amount,      col_4  from my_table;  

Is there any way I can assign a value to be available on the query context no matter the order? I want to avoid duplicating code and make the query more efficient by avoiding redundant calculations.

How could the user enter some fields after the CallbackQuery (aiogram)?

Posted: 09 Oct 2021 08:32 AM PDT

I'm developing a telegram bot and I need to get some personal data. After the user has clicked on the sign in button, the database should receive his ID, and he himself should fill in some fields (phone, email, name). But I don't understand how this can be implemented in a request. Can you help with this?

main file:

@dp.callback_query_handler(text='reg')  @dp.callback_query_handler(text='cansel_1')  async def registration(query:types.CallbackQuery):      answ_data = query.data      if answ_data == 'reg':          if not db.client_exists(query.from_user.id):              db.add_client(query.from_user.id)              await bot.send_message(query.from_user.id, text=f'Name:')              client_name=query.message                await bot.send_message(query.from_user.id, text=f'Phone:')              cl_phone=query.message                await bot.send_message(query.from_user.id, text=f'E-mail:')              cl_email=query.message              db.add_client(query.from_user.id, client_name, cl_phone, cl_email)          else:              db.update_status(query.from_user.id, True)              await bot.send_message('You have joined in our club',reply_markup=nav.next_btn_1)        elif answ_data == 'cansel_1':          await bot.send_message(query.from_user.id,                                 text='We hope you will back!')      else:          await bot.send_message(query.from_user.id,                                 text='I don't understand what you mean')  

db file:

def __init__(self, database_file):      self.connection = sqlite3.connect(database_file)      self.cursor=self.connection.cursor()    def get_new_user(self, status = True):      with self.connection:          return self.cursor.execute("SELECT * FROM 'clients' WHERE 'stutus' = ?", (status,)).fetchall()    def client_exists(self, user_id):      result = self.cursor.execute("SELECT * FROM 'clients' WHERE 'user_id' = ?", (user_id,))      return bool(len(result.fetchall()))    def get_user_id (self, user_id):      result = self.cursor.execute("SELECT 'id' FROM 'clients' WHERE 'user_id'= ?", (user_id,))      return result.fetchall()[0]      def add_client(self, user_id, client_name, cl_phone, cl_email, status = True):      with self.connection:          return self.cursor.execute("INSERT INTO 'clients' ('user_id', 'status', 'Name', 'Phone', 'Email') VALUES (?, ?, ?, ?, ?)",                                     (user_id, status, client_name, cl_phone, cl_email,))  

Now I have this error when I try to : TypeError: add_client() missing 3 required positional arguments: 'client_name', 'cl_phone', and 'cl_email'

Removes punctuation and turn comments into a list of words

Posted: 09 Oct 2021 08:31 AM PDT

I am trying to make a function that will remove punctuation while turning the "comment" into a word of list. When typing this:

def convert(lst):      return " " .join(lst).split()  lst = ["Good for the price but poor Bluetooth connections."]  print(lst)  

I get ['Good for the price but poor Bluetooth connections.'] in return.

Any solutions?

Change only one element after clicking other

Posted: 09 Oct 2021 08:32 AM PDT

I have the following problem:

I would like to change the value of an input field, which is next to an another element, which will be clicked.

HTML:

<div>     <a id="{$sArticle.articleID}" class="minus"><i class="icon-minus-wide"></i></a>          <input class="quantityNum--input quantity{$sArticle.articleID}" name="sQuantity"      type="text" value="{$sArticle.minpurchase}">       <a id="{$sArticle.articleID}" class="plus"><i class="icon-plus-wide"></i></a>  </div>  

JS:

     $(document).on('click', ".plus", function (event) {          let currentTarget = event.currentTarget;            let idOfClickedElement = $(currentTarget).attr('id');            let currentQuantity = Number($('.quantity' + idOfClickedElement).val());            $(this).parent().find(".quantity" + idOfClickedElement).val(currentQuantity + 1)      });  

There are other input fields which are the same like in the example. Those value changes also, but I want only one.

Aggregate using values within a column

Posted: 09 Oct 2021 08:33 AM PDT

I have a dataframe:

Region Month
0 AB 1
1 AB 1
2 AB 2
3 BC 3
4 BC 4
5 BC 5

How do I turn this dataframe to the below where the distinct values of the region are columns and the distinct value of each month are the rows. The values are the sum of count of all stance of the region/month combination. Since I have a the list of Region and Month I can also specify them as a list, as long as it gives me the view below.

I used df.groupby(['Region', 'Month'], as_index=True).agg({"Month": "count"}) however the layout is different where the month is a column instead of the layout below.

AB BC
JAN 2 0
FEB 1 0
MAR 0 1
APR 0 1
MAY 0 1
JUN 0 0
JUL 0 0
AUG 0 0
SEP 0 0
OCT 0 0
NOV 0 0
DEC 0 0

After cloning any flutter project I can not resolve dependencies?

Posted: 09 Oct 2021 08:31 AM PDT

I want to clone open source projects , I face a hole punch of errors after tapping pub get , all dependencies cannot be resolved and many of code are out of date , so how can I overcome this ?

a sample of errors

To transfer only objects greater than 100MB to AWS Glacier from S3 Standard using AWS Lifecycle Management Policy

Posted: 09 Oct 2021 08:33 AM PDT

I've 50TB of data in S3 Standard bucket. I want to push objects that are greater that 100MB as well as 30 days old to AWS Glacier using Lifecycle Management Policy. Can you let me know how to move only objects that are greater than 100MB in size. Thanks

EF Core 5 - how to change auto-generated foreign key column name?

Posted: 09 Oct 2021 08:33 AM PDT

In EF Core 5 I have a class called Chart which has these 4 properties:

        public virtual ICollection<ChartField> Filters { get; set; }            public virtual ICollection<ChartField> HiddenFilters { get; set; }            public virtual ICollection<ChartField> AddAllFilters { get; set; }            public virtual ICollection<ChartField> Series { get; set; }  

... The ChartField table get's generated with column names like so:

  • ChartId
  • ChartId1
  • ChartId2
  • ChartId3

... How can I tell EF Core 5 to change ChartField column names to something like:

  • ChartId_MainChart
  • ChartId_SecondaryChart
  • ChartId_ExtraChart
  • ChartId_AnotherOne

is there an annotation or way to override the foreign key column names?

Adding data to FlatList clears the whole list

Posted: 09 Oct 2021 08:32 AM PDT

I am new to react-native. I have a flatlist, that takes data from "state". This works. Then, I added a new function in order to add new data to the flatlist (additionally to the existing data).

As soon as I click on the "delete" button ( don't mind the name) the data of the flatlist is being deleted completely. I want the output to be like

Object 1

Object 2

Object 3 (has been added after button click)

What am I doing wrong? Can you please explain me the reason?

EDIT: I get this warning, but no error.

VirtualizedList: missing keys for items, make sure to specify a key or id property on each item or provide a custom keyExtractor.,

import React, { Component } from "react";  import { Text, View, StyleSheet, Button, FlatList } from "react-native";    class App extends Component {    state = {      counter: 0,      initialElements: [        { id: "0", text: "Object 1" },        { id: "1", text: "Object 2" },      ],    };      render() {      const currentCounter = this.state.counter;      const exampleState = this.state.initialElements;        const addElement = () => {        let newArray = [...exampleState, { id: "2", text: "Object 3" }];        this.setState({          initialElements: [newArray],        });      };        return (        <View style={styles.container}>          <View style={styles.counter}>            <Text style={styles.textStyle}>{currentCounter}</Text>          </View>            <View style={styles.deleteButton}>            <Button              title="Hello"              onPress={() =>                this.setState({                  counter: currentCounter + 1,                })              }            ></Button>            <View style={styles.space}></View>            <Button title="Delete" onPress={addElement}></Button>{" "}            {/* as soon as I click here, the content of the list is being deleted */}          </View>            <FlatList            style={styles.listStyle}            key={(item) => item.id}            data={exampleState}            renderItem={(item) => <Text>{item.item.text}</Text>}          />        </View>      );    }  }    const styles = StyleSheet.create({    container: {      backgroundColor: "#fff",      justifyContent: "center",      flex: 1,      flexDirection: "column",      alignItems: "center",    },    counter: {      flexDirection: "row",      justifyContent: "center",    },    deleteButton: {      flexDirection: "row",      margin: 5,      marginTop: 100,    },    space: {      width: 5,      height: 5,    },    textStyle: {      margin: 80,      fontSize: 100,    },      listStyle: {      flexDirection: "column",    },    item: {      padding: 10,      fontSize: 18,      height: 44,    },  });    export default App;  

Intermittent hang during periodic update using WPF MVVM

Posted: 09 Oct 2021 08:32 AM PDT

I am developing an application using WPF MVVM. My program needs to quickly update a lot of data and display it in the UI. I have a function that reads 2000 data from shared memory every 1millisecond and updates the UI. At this time, there is a phenomenon that the data update is temporarily stopped every 2-3 seconds. There was no stopping when updating from code behind without using MVVM. To improve this phenomenon, the update cycle was changed to 100 milliseconds, but the freeze did not improve. If you have experienced something like this, please share your solution with me. The source code is a sample of the problem from my product. Thank you very much.

View

<UserControl x:Class="BindingHang.Views.MainView"               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"                xmlns:d="http://schemas.microsoft.com/expression/blend/2008"                xmlns:local="clr-namespace:BindingHang.Views"               mc:Ignorable="d"                d:DesignHeight="450" d:DesignWidth="800">      <UserControl.Resources>          <Style TargetType="ListView">              <Setter Property="IsSynchronizedWithCurrentItem" Value="True" />              <Setter Property="Margin" Value="5" />          </Style>      </UserControl.Resources>      <Grid>          <Grid.RowDefinitions>              <RowDefinition />              <RowDefinition />          </Grid.RowDefinitions>            <Grid.ColumnDefinitions>              <ColumnDefinition />              <ColumnDefinition />              <ColumnDefinition />              <ColumnDefinition />          </Grid.ColumnDefinitions>          <ListView Grid.Row="0" Grid.Column="0" ItemsSource="{Binding Path=Changes1}">              <ListView.View>                  <GridView>                      <GridView.Columns>                          <GridViewColumn DisplayMemberBinding="{Binding Path=Name}" Header="Name" />                          <GridViewColumn DisplayMemberBinding="{Binding Path=Value}" Header="Value" Width="100" />                      </GridView.Columns>                  </GridView>              </ListView.View>          </ListView>          <ListView Grid.Row="0" Grid.Column="1" ItemsSource="{Binding Path=Changes2}">              <ListView.View>                  <GridView>                      <GridView.Columns>                          <GridViewColumn DisplayMemberBinding="{Binding Path=Name}" Header="Name" />                          <GridViewColumn DisplayMemberBinding="{Binding Path=Value}" Header="Value" Width="100" />                      </GridView.Columns>                  </GridView>              </ListView.View>          </ListView>          <ListView Grid.Row="0" Grid.Column="2" ItemsSource="{Binding Path=Changes3}">              <ListView.View>                  <GridView>                      <GridView.Columns>                          <GridViewColumn DisplayMemberBinding="{Binding Path=Name}" Header="Name" />                          <GridViewColumn DisplayMemberBinding="{Binding Path=Value}" Header="Value" Width="100" />                      </GridView.Columns>                  </GridView>              </ListView.View>          </ListView>          <ListView Grid.Row="0" Grid.Column="3" ItemsSource="{Binding Path=Changes4}">              <ListView.View>                  <GridView>                      <GridView.Columns>                          <GridViewColumn DisplayMemberBinding="{Binding Path=Name}" Header="Name" />                          <GridViewColumn DisplayMemberBinding="{Binding Path=Value}" Header="Value" Width="100" />                      </GridView.Columns>                  </GridView>              </ListView.View>          </ListView>          <ListView Grid.Row="1" Grid.Column="0" ItemsSource="{Binding Path=Changes5}">              <ListView.View>                  <GridView>                      <GridView.Columns>                          <GridViewColumn DisplayMemberBinding="{Binding Path=Name}" Header="Name" />                          <GridViewColumn DisplayMemberBinding="{Binding Path=Value}" Header="Value" Width="100" />                      </GridView.Columns>                  </GridView>              </ListView.View>          </ListView>          <ListView Grid.Row="1" Grid.Column="1" ItemsSource="{Binding Path=Changes6}">              <ListView.View>                  <GridView>                      <GridView.Columns>                          <GridViewColumn DisplayMemberBinding="{Binding Path=Name}" Header="Name" />                          <GridViewColumn DisplayMemberBinding="{Binding Path=Value}" Header="Value" Width="100" />                      </GridView.Columns>                  </GridView>              </ListView.View>          </ListView>          <ListView Grid.Row="1" Grid.Column="2" ItemsSource="{Binding Path=Changes7}">              <ListView.View>                  <GridView>                      <GridView.Columns>                          <GridViewColumn DisplayMemberBinding="{Binding Path=Name}" Header="Name" />                          <GridViewColumn DisplayMemberBinding="{Binding Path=Value}" Header="Value" Width="100" />                      </GridView.Columns>                  </GridView>              </ListView.View>          </ListView>          <ListView Grid.Row="1" Grid.Column="3" ItemsSource="{Binding Path=Changes8}">              <ListView.View>                  <GridView>                      <GridView.Columns>                          <GridViewColumn DisplayMemberBinding="{Binding Path=Name}" Header="Name" />                          <GridViewColumn DisplayMemberBinding="{Binding Path=Value}" Header="Value" Width="100" />                      </GridView.Columns>                  </GridView>              </ListView.View>          </ListView>      </Grid>  </UserControl>  

ViewModel

using BindingHang.Models;  using System;  using System.Collections.Generic;  using System.Linq;  using System.Text;  using System.Threading.Tasks;  using System.Windows;    namespace BindingHang.ViewModels  {      public class MainVM : ViewModelBase      {          #region << Fields >>          private readonly int _maxCount = 1000;          private readonly int _delay = 20;          

No comments:

Post a Comment