satoshi-2000/llms-suitable huggingface dataset:
Question: Why is the 'Growth Estimates' table not being detected by beautifulsoup on this website?

I tried to webscrape the data from the below url to get the data from the "Growth Estimates" table using beautiful soup & requests but it can't seem to pick the table up. However when using the inspection tool I can see there is a table there to pull data from and I couldn't see anything about it being pulled dynamically, but I could be wrong.
url = https://finance.yahoo.com/quote/AAPL/analysis?p=AAPL
Is someone able to explain the issue and offer a solution?
Thank you!
import requests
from bs4 import BeautifulSoup

def get_growth_data(symbol):
    url = "https://finance.yahoo.com/quote/{symbol}/analysis?p={symbol}"
    response = requests.get(url)
    soup = BeautifulSoup(response.text, "html.parser")

    # Find the table containing the growth data
    table = soup.find("table", class_="W(100%) M(0) BdB Bdc($seperatorColor) Mb(25px)")

    if table is None:
        print("Table not found.")
        return []

    # Extract the growth values from the table
    growth_values = []
    rows = table.find_all("tr")
    for row in rows:
        columns = row.find_all("td")
        if len(columns) >= 2:
            growth_values.append(columns[1].text)

    return growth_values

symbol = 'AAPL'
growth_data = get_growth_data(symbol)
print(growth_data)




Answer:
To get correct response from the server set User-Agent HTTP header in your request:
import pandas as pd
import requests
from bs4 import BeautifulSoup

url = 'https://finance.yahoo.com/quote/AAPL/analysis?p=AAPL'
headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/113.0'}
soup = BeautifulSoup(requests.get(url, headers=headers).content, 'html.parser')

table = soup.select_one('table:-soup-contains("Growth Estimates")')
df = pd.read_html(str(table))[0]

print(df)

Prints:
           Growth Estimates    AAPL  Industry  Sector(s)  S&P 500
0              Current Qtr.  -0.80%       NaN        NaN      NaN
1                 Next Qtr.   5.40%       NaN        NaN      NaN
2              Current Year  -2.30%       NaN        NaN      NaN
3                 Next Year   9.90%       NaN        NaN      NaN
4  Next 5 Years (per annum)   8.02%       NaN        NaN      NaN
5  Past 5 Years (per annum)  23.64%       NaN        NaN      NaN
Question: OptInt type function in Python

import pandas as pd
import json

    mass=[]
    fall=[]
    year=[]

req = requests.get("https://data.nasa.gov/resource/y77d-th95.json")
response =req.json()

for i in range(0,len(response)):
    mass.append(response[i]['mass']) 
    fall.append(response[i]['fall'])
    year.append(response[i]['year'])

I handle keyError with the help of Exception handling. If i got keyerror i added NAN value.
As java have function like OptString whenever we get keyerror it add default value.
I just want to get all data in list but via using optString type method.
Can you give any example ?
Thanks ,


Answer:
You can use dict.get to provide a default value as the second argument.
For example:
from math import nan

for obj in response:
    mass.append(obj.get('mass', nan))
    fall.append(obj.get('fall', nan))
    year.append(obj.get('year', nan))
Question: Owner information not available from Google Cloud Storage blob

I am using get_blob using the python API. All kinds of information about the blob is available, but owner is set to None. My application needs to know who last updated the file in GCS.  Any help would be appreciated!
I tried calling reload with projection set to full, as suggested elsewhere, but it didn’t help. I tried setting acl as well as uniform permissions on the bucket, but it was the same result.
I would be willing to change the bucket permissions to anything (other than making it public) that would allow me to get the file updater/owner information.


Answer:
In Google Cloud Storage, buckets are owned by the project. Users (IAM principals) are not owners of a bucket. Permissions are granted to users to access a bucket and its objects. The logs record who created a bucket.
For updates, review Audit Logging. Google records changes to a resource's metadata.
Usage logs & storage logs
Question: Fix error RecyclerView: No adapter attached; skipping layout

Just implemented RecyclerView in my code, replacing ListView.
Everything works fine. The data is displayed.
But error messages are being logged:
RecyclerView: No adapter attached; skipping layout
I have read other questions related to the same problem but none of them help.


Answer:
i have this problem , a few time problem is recycleView put in ScrollView object
After checking implementation, the reason appears to be the following. If RecyclerView gets put into a ScrollView, then during measure step its height is unspecified (because ScrollView allows any height) and, as a result, gets equal to minimum height (as per implementation) which is apparently zero.
You have couple of options for fixing this:
Set a certain height to RecyclerView
Set ScrollView.fillViewport to true
Or keep RecyclerView outside of ScrollView. In my opinion, this is the best option by far. If RecyclerView height is not limited - which is the case when it's put into ScrollView - then all Adapter's views have enough place vertically and get created all at once. There is no view recycling anymore which kinda breaks the purpose of RecyclerView .
(Can be followed for android.support.v4.widget.NestedScrollView as well)
Question: Pygame get_rect() is not running

get_rect() is not running
I was trying to make a simple game for educational purposes using the pygame module. I encountered this error. I would be glad if you can help
import pygame 
import random
import sys 
import os 

pygame.init()
balikci_konum = "E:/E/Python/Python-eski/Oyuncalismalari/balik_avlama_oyunu/textures/balikci.png"
genislik = 1000
yukseklik = 600 

ekran = pygame.display.set_mode((genislik,yukseklik))

# ...

class Balik(pygame.sprite.Sprite):
    def __init__(self,x,y,resim,tip):
        super().__init__()
        self.image = resim 
        self.rect = self.image.get_rect()
        self.rect.topleft = (x,y)
        self.tip = tip 
        self.hiz = random.randint(0,13)
        self.yonx= random.choice([1,-1])
        self.yony= random.choice([1,-1])
        
    def update(self):
        self.rect.x = self.hiz*self.yonx
        self.rect.y = self.hiz*self.yony
        
        if self.rect.left <=0 or self.rect.right >= genislik : 
            self.yonx *=-1
            
        if self.rect.top <=0 or self.rect.bottom >= yukseklik : 
            self.yony *=-1
     
#Balık Grupları 
balik1 = pygame.image.load("E:/E/Python/Python-eski/Oyuncalismalari/balik_avlama_oyunu/textures/balik1.png")
balik2 = pygame.image.load("E:/E/Python/Python-eski/Oyuncalismalari/balik_avlama_oyunu/textures/balik2.png")

balik_grup = pygame.sprite.Group()
balik = Balik(random.randint(0,genislik-32),random.randint(0,yukseklik-32),balik1,0)
balik_grup.add(balik)

balik = Balik(random.randint(0,genislik-32),random.randint(0,yukseklik-32),balik2,0)
balik_grup.add(balik)

# ...

that is all of my code
i tried relocating objects but still get_rect() function doesn't work


Answer:
To move the objects you have to change the position with += instead of setting the position with an assignment (=):
self.rect.x = self.hiz*self.yonx
self.rect.y = self.hiz*self.yony
self.rect.x += self.hiz*self.yonx
self.rect.y += self.hiz*self.yony
Question: Javascript construct trap not working in class returning proxy

I am trying to create a little javascript two way form binder using proxies. I am stuck on how I can intercept 'new' calls. I use a 'construct' trap but it doesn't fire. Here is my code, I have removed the stuff that is not relivant for my specific problem
    class BoundObject {

        constructor(object, element) {

            // distribute object properties into "this"
            for (const prop in object) {
                this[prop] = object[prop]
            }

            return new Proxy(this, {

                construct:(target, args) => {
                    console.log(`Creating a new ${target.name}`) // why is this not fired?
                    return Reflect.construct(...args)
                },
                set: (target, prop, val, receiver) => {
                    console.log(`attempting to set ${prop}=${val} type ${typeof val}`);

                    return Reflect.set(target, prop, val) 
                }
            })
        }
    }

    // create an instance of our BoundObject class, passing in an object and an HTML element
    const user = new BoundObject({name:'fred'},document.querySelector('#user-form'))    // why is the 'construct' call not intercepted?
    user.name = 'mary' // set user name. The 'set' call is sucessfully intercepted

The set trap works, but the construct trap fails to fire.  I suspect this is to do with javascript deep magic around 'this' but cannot figure it out
How can I intercept the construction of the proxy object my class returns?


Answer:
The construct trap is only called when the [[Construct]] internal method is invoked on the proxy itself. This could be caused by using the new operator. However, in this case, the Proxy is returned as a result of calling new on the BoundObject constructor; new was not called on the proxy itself.
Here is an example of where the construct trap could be called.


function MyObj() {}
const proxy = new Proxy(MyObj, {
  construct(target, args) {
    console.log(args);
    return new target(...args);
  }
});
new proxy('something');
Question: How can I fix line breaks output by script(1) utility?

I have the following lftp script to copy files from a remote to local:
env TERM=dumb script -a $LOGSTDOUT -c "$(cat <<- EOF
    lftp $PROTOCOL://$URL -u ${USER},${PASS} << EOFF
    set dns:fatal-timeout never
    set sftp:auto-confirm yes
    set mirror:use-pget-n 50
    set mirror:parallel-transfer-count 2
    set mirror:parallel-directories yes
    set mirror:include-regex $REGEX
    set log:enabled/xfer yes
    set log:file/xfer $LOG
    set xfer:use-temp-file yes
    set xfer:temp-file-name *.lftp
    mirror -c -v --loop --Remove-source-dirs "$REMOTEDIR" "$LOCALDIR"
    quit
    EOFF
EOF
)"

I am capturing terminal output with the script(1) utility. The env TERM=dumb is just a random piece of code I found to disable ANSI escape codes.
My problem is that the line breaks of the output log file get quiet mangled. It seems to be using CR and LF. I discovered more information here and it seems this is by design. Though I'm not sure how to fix it.
These line endings cause issues when viewing the logs in lnav:

The reason for this becomes quickly apparent upon inspecting the raw text:

I have thought of some potential options, but not sure how to implement:

Fix the output of the script(1) utility so that single CR are converted to LF. Maybe this can be achieved with piping or some arguement?
A hack for lnav to treat CR as LF when displaying in the GUI.

Anyone know how I can fix these line breaks so it shows correctly in lnav?


Answer:
Try replacing
... script -a $LOGSTDOUT ...

with
... script -a >(tr -d '\r' >"$LOGSTDOUT") ...


See the Process Substitution section on the Bash Reference Manual for an explanation of >(...).
Note that ALL_UPPERCASE variable names (like LOGSTDOUT) are best avoided because there is a danger of clashes with the large number of special ALL_UPPERCASE variables that are used in shell programming.  See Correct Bash and shell script variable capitalization.
The quotes on $LOGSTDOUT are necessary in general.  Use Shellcheck to find common problems with shell code, including missing quotes.
Question: PySpark and Postgres: JDBC connection error

Issues connecting PySpark & Postgres
I've scoured the Apache docs, Stackoverflow and watched youtube tutorials but can't seem to find an issue to my exact issue. I have clearly pointed to the postgres executable jar file but it doesn't I can't seem to be able to read from the db. Below is an extract from my script. The properties parameter contains the user, password and driver ("org.postgresql.Driver") details in the form of a dictionary.
Anybody know what I am missing? I get the error:

IllegalArgumentException: requirement failed: the driver could not open a JDBC connection. Check the URL

Added context: I am using Postgres 15, Spark 3.4.0 and Python 3.10
spark = SparkSession\
        .builder\
        .config('spark.jars','C:\Program Files\Spark\spark-3.4.0-bin-hadoop3\jars\postgresql-42.6.0.jar')\
        .getOrCreate()

    spark.read.jdbc(
        url=f'jdbc:postgresql//localhost:5432/ag',
        table='customers',
        properties=props).load()



Answer:
Seems like your URL is missing a : character.
You've written
jdbc:postgresql//localhost...

instead of
jdbc:postgresql://localhost...
Question: What constitutes a directive in C++, and how can I use them effectively?

How do you exactly define a directive in programming?
#include is a directive, and using namespace std is a directive as well, assuming that I  am correct.
What actually makes a sentence or word a directive?
I tried reading from different sources, but all lead to no avail. I  am new to programming and I hope to grasp a good understanding of a directive.


Answer:
You mentioned two different programming constructs in your question: 1) the #include pre-processing directive and 2) the using namespace directive.
Each of these constructs is literally referred to as a "directive" in the documentation, but they are completely different things. I can see how that could cause confusion.
Both the pre-processing directives and the using directive are not something that the user gets to define. They have a fixed meaning in the language. They can be used with different arguments to achieve different results.
Directives like #include can be used to direct what source code is used in the compilation. For example, #include <iostream> will cause the file iostream to be included. There are numerous other pre-processor directives, but for starting out, #include is by far the most important.
A directive like using std::cout instructs the compiler to bring the std::cout symbol into the current namespace so it can be referenced as simply cout.
I hope this helps clear up the confusion.
Question: Grouping dictionary data from a list and storing in another dictionary

I am currently working on a big data set where the data is stored into list with dictionaries (format shown below)
List = [{ID001: Report-1, ID002: Report-1, ID003: Report-1}, {ID001: Report-2, ID005: Report-5}…..]

I am trying to group and print a list with one dictionary that contains all ID’s from all dictionaries in the above list with related values (in this case report-1, report-2…)
result_List = {ID001: [Report-1, Report-2, Report-5], ID002: [Report-3, Report-6, Report-23]}

I thought of using for loop, but once the first dictionary is done looping through all the other dictionaries in list, it has to store unique ID’s in the result_List.
The code itself contains lot of loops, which I believe too complex for a list of 200 dictionaries with data.
I am looking for something with Pandas or Numpy with relatively less complex. Can anyone suggest the best way to do this kind of data crunch?


Answer:
This way it can be done.
data =  [{ID001: Report-1, ID002: Report-1, ID003: Report-1}, {ID001: Report-2, ID005: Report-5}…..]
d = pd.DataFrame.from_records(data)
res = d.to_dict("list")
print(res)
Question: Retrieve issue number from string for comic

I'm not great with RegEx.  I need to retrieve the issue number from the long title of a comic book that includes its name and sometimes the artist's name.  Usually the issue number is the last number in the string, but not always.  Here are 6 examples that capture the range of variations I'm looking at:
STAR WARS: DOCTOR APHRA 32 CHRIS SPROUSE RETURN OF THE JEDI 40TH ANNIVERSARY VARIANT
DEADPOOL 7
X-23: DEADLY REGENESIS 3 GERALD PAREL VARIANT
SPIDER-MAN 2099: DARK GENESIS 5
THE GODFORSAKEN 99 OF KRONOS 2 KEN GRAGGINS VARIANT
Teenage Mutant Ninja Turtles: Saturday Morning Adventures (2023-) #1 Variant RI (10) (Dooney)

I'm using VBA and this is my current function:
Function ExtractText(c As Range) As String
    Dim rgx As RegExp
    Dim match As match
    Dim mc As MatchCollection
    Dim sComicNo As String, sPattern As Variant
    Dim lPos As Long, x As Long

    sComicNo = ""
    sPattern = Array(" [0-9] ", " #[0-9] ", " [0-9][0-9] ", " #[0-9][0-9] ", " [0-9][0-9]", " #[0-9][0-9]", " [0-9]", " #[0-9]")
    lPos = 0
    
    Set rgx = New RegExp
    
    On Error GoTo ErrHandler
    
    Do While sComicNo = ""
        
        With rgx
            .Pattern = sPattern(x)
            .Global = True
        
            If .Test(c.Value) Then
                Set mc = .Execute(c.Value)
                
                If mc.Count > 0 Then
                    Set match = mc.Item(mc.Count - 1)
                Else
                    ExtractText = ""
                End If
                
                lPos = match.FirstIndex
                sComicNo = WorksheetFunction.Trim(match.Value) & "|" & lPos
            Else
                sComicNo = ""
            End If
            
            x = x + 1
            
            If x > 8 Then
                ExtractText = sComicNo
                Exit Function
            End If
        
        End With
        
    Loop
    
    ExtractText = sComicNo
    
ErrHandler:

    Exit Function
    
End Function

This pattern matches all my examples except the Spider-Man 2099, but there are other possible variations I'm overlooking.  It is also retrieving the position of the match for a separate purpose.  I'm trying to be as restrictive as possible by using patterns in a sequence that will retrieve very specific cases and gradually work up from there.


Answer:
I don't know VBA, but by trying to comprehend the code I think your regex can be simplified to this:
\s      # Match a whitespace,
#?      # an optional '#', then
\d\d?   # 1 or 2 digits, followed by
\b      # a word boundary (prevents numbers with 3+ digits from being matched).

Try it on regex101.com.
Alternatively, you can use a lookbehind to skip the trimming part:
(?<=\s)#?\d\d?\b

...in which (?<=\s) means "match something preceded by a whitespace".
Try it on regex101.com.
Question: How to make RTL to support right to left languages only in a column in XAML WPF VB.NET

If using FlowDirection="RightToLeft" will change the whole datagrid right to left and solves the problem.
But my grid has both LTR and RTL contents. Some columns are LTR and some other column are RTL.
So please help me on this that how can I only set one column as RTL?
Thanks.


Answer:
At last I found the answer.
Here it is:
   <DataGridTextColumn ...>
        <DataGridTextColumn.ElementStyle>
            <Style TargetType="TextBlock">
                <Setter Property="FlowDirection" Value="LeftToRight" />
            </Style>
        </DataGridTextColumn.ElementStyle>
        <DataGridTextColumn.EditingElementStyle>
            <Style TargetType="TextBox">
                <Setter Property="FlowDirection" Value="LeftToRight" />
            </Style>
        </DataGridTextColumn.EditingElementStyle>
    </DataGridTextColumn>