<jupyter_start><jupyter_text>MIT LicenseCopyright (c) [year] [fullname]Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE. **Import Reference**<jupyter_code>import requests
from lxml import html   
import numpy as np
import pandas as pd
import json<jupyter_output><empty_output><jupyter_text>**Json Processing**<jupyter_code>portfolio = json.load(open("./portfolio.json","r"))
portfolioset = set(portfolio)<jupyter_output><empty_output><jupyter_text>**Call FinWiz site**<jupyter_code>tickers = ','.join(str(s) for s in portfolioset)
URL = 'https://www.finviz.com/screener.ashx?v=110&t='+tickers
page = requests.get(URL)
tree = html.fromstring(page.content)
screener = tree.xpath('//table[@bgcolor="#d3d3d3"]/tr')<jupyter_output><empty_output><jupyter_text>**Post process HTML scrapping**<jupyter_code># screener
header=True
stocks=[]
for stock in screener:
    if header:
        headerarr = []
        headerarr.append("Group")
        headerarr.append(stock.xpath('./td[2]/text()')[0])
        headerarr.append(stock.xpath('./td[3]/text()')[0])
        headerarr.append(stock.xpath('./td[4]/text()')[0])
        headerarr.append(stock.xpath('./td[9]/text()')[0])
        headerarr.append(stock.xpath('./td[10]/text()')[0])
        headerarr.append("Unit Cost")
        headerarr.append("Qty")
        headerarr.append("Total Cost")
        headerarr.append("UnRealized Gain/Loss")
        headerarr.append("UnRealized Gain/Loss %")
        stocks.append(headerarr)
        header=False
    else:
        uc = "0"
        qty = "0"
        unrgl = 0
        unrglpct = 0
        price = stock.xpath('./td[9]/a/span/text()')[0] #Price

        if stock.xpath('./td[2]/a/text()')[0] in portfolioset:
            uc = portfolio[stock.xpath('./td[2]/a/text()')[0]]["unitcost"]
            qty = portfolio[stock.xpath('./td[2]/a/text()')[0]]["qty"]
            unrgl = (float(price) - float(uc)) * float(qty)
            unrglpct = ((float(price) - float(uc)) / float(uc))
            
        arr = [] #stock.xpath('./td/a/text()')
        arr.append(portfolio[stock.xpath('./td[2]/a/text()')[0]]["group"]) #Group
        arr.append(stock.xpath('./td[2]/a/text()')[0]) #Ticker
        arr.append(stock.xpath('./td[3]/a/text()')[0]) #Company
        arr.append(stock.xpath('./td[4]/a/text()')[0]) #Sector
        arr.append("${0}".format(price))
        arr.append(stock.xpath('./td[10]/a/span/text()')[0]) #Change
        arr.append("${0}".format(uc))
        arr.append(qty)
        arr.append("${:.2f}".format(float(uc) * float(qty)))
        arr.append("${:.2f}".format(unrgl))
        arr.append("{:.2%}".format(unrglpct))
        stocks.append(arr)
# print(stocks)<jupyter_output><empty_output><jupyter_text>**Attach it to DataFrame**<jupyter_code>dataset = pd.DataFrame(stocks)
headers=dataset.iloc[0]
dataset=dataset[1:]
dataset.rename(columns = headers)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16081186572989853, 'fraction_numerical': 0.012230028623471247, 'mean_word_length': 3.96, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '420707', 'license': 'MIT', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1260, 'n_words': 275, 'path': 'portfolio.ipynb', 'repo_name': 'maharishi/portfolio-tracker', 'size': '3843'}