Search This Blog

Wednesday, November 27, 2019

IText - Alignment, Page Size Html to Pdf

Document document = new Document ();
PdfWriter writer = PdfWriter.getInstance ( document, new FileOutputStream ( "d:/fhpl.pdf" ) );
document.setMargins ( 0.1f, 0.1f, 0.1f, 0.1f );
document.setPageSize ( PageSize.A3 );
document.open ();
XMLWorkerHelper.getInstance ().parseXHtml ( writer, document, new FileInputStream ( "d:/fhpl1.html" ) );
document.close ();



Note: Before document.open(); to place all your customize settings.

Flying Saucer HTML to PDF

Add this maven

<!-- https://mvnrepository.com/artifact/org.xhtmlrenderer/flying-saucer-pdf-itext5 -->

<dependency>

    <groupId>org.xhtmlrenderer</groupId>

    <artifactId>flying-saucer-pdf-itext5</artifactId>

    <version>9.1.19</version>

</dependency>


Code 

        String inputFile = "d:/xxx.html";
        String url = new File(inputFile).toURI().toURL().toString();
        String outputFile = "d:/xxx.pdf";
        OutputStream os = new FileOutputStream(outputFile);
       
        ITextRenderer renderer = new ITextRenderer();
        renderer.setDocument(url);
        renderer.layout();
        renderer.createPDF(os);
       

        os.close();


Note
It will throw if any " QName production: QName::=(NCName':')?NCName. ' Exception in thread "main" org.xhtmlrenderer.util.XRRuntimeException: "  Then your html tag has problem. correct that html tag and re run it.

for ex: <Table width: 50%"> 
     to
      <table width="50%">

Tuesday, November 26, 2019

Linux nMap commands

nmap
nmap -O
nmap -sA
nmap -r
nmap -sS
nmap -sP
nmap --iflist
nmap -PS
nmap -PO
nmap -PU
nmap -sU
nmap -v -sT -PN --spoof-mac 0
nmap -v -sS -A -T4

Thursday, November 7, 2019

NSE options Data Pulling with beta.nseindia.com

Beta version they are giving it as JSON which is very easy for us.

See the sample url. 

1. JSON output,
2. Directly use the JSON for your business logic.
3. Before install requests, simplejson plugin
     pip install simplejson
     pip install requests

Same for older version - sample code and output

http://drvijayy2k2.blogspot.com/2019/08/python-code-to-pull-nse-option.html

Code

import requests
import simplejson as json

result = requests.get ( "https://beta.nseindia.com/api/quote-derivative?symbol=NIFTY&identifier=OPTIDXNIFTY07-11-2019" );
resultJson = json.loads( result.content )
#print ( resultJson["info"] );
strikePricesDetailsJson = resultJson["stocks"]
for strikePrice in strikePricesDetailsJson:
    spDetails = strikePrice["metadata"];
    #print ( spDetails );
    print ( spDetails["optionType"] , " : ", spDetails["strikePrice"] , " : ", spDetails["lastPrice"]);



Output

Call  :  12350  :  0
Put  :  11050  :  0

Call  :  12750  :  0


{'metadata': {'instrumentType': 'Index Options', 'expiryDate': '28-Dec-2023', 'optionType': 'Put', 'strikePrice': 12700, 'identifier': 'OPTIDXNIFTY28-12-2023PE12700.00', 'openPrice': 0, 'highPrice': 0, 'lowPrice': 0, 'closePrice': 0, 'prevClose': 1005, 'lastPrice': 0, 'change': -1005, 'pChange': -100, 'numberOfContractsTraded': 0, 'totalTurnover': 0}, 'underlyingValue': 11998.1, 'volumeFreezeQuantity': 5001, 'marketDeptOrderBook': {'totalBuyQuantity': 225, 'totalSellQuantity': 0, 'bid': [{'price': 645.05, 'quantity': 75}, {'price': 645, 'quantity': 75}, {'price': 597, 'quantity': 75}, {'price': 0, 'quantity': 0}, {'price': 0, 'quantity': 0}], 'ask': [{'price': 0, 'quantity': 0}, {'price': 645, 'quantity': 0}, {'price': 0, 'quantity': 0}, {'price': 0, 'quantity': 0}, {'price': 0, 'quantity': 0}], 'carryOfCost': {'price': {'bestBuy': 645.05, 'bestSell': 0, 'lastPrice': 0}, 'carry': {'bestBuy': -70.5660812600072, 'bestSell': 0, 'lastPrice': 0}}, 'tradeInfo': {'tradedVolume': 0, 'value': 0, 'vmap': 0, 'premiumTurnover': 0, 'openInterest': 6, 'changeinOpenInterest': 0, 'pchangeinOpenInterest': 0, 'marketLot': 75}, 'otherInfo': {'settlementPrice': 0, 'dailyvolatility': 0.91, 'annualisedVolatility': 17.45, 'impliedVolatility': 0, 'clientWisePositionLimits': 19597661, 'marketWidePositionLimits': 0}}}



Hit Counter


View My Stats