Search This Blog

Tuesday, December 24, 2019

Flask Ask - modulenotfounderror no module named 'pip.req' flask-ask

Try like below.


pip install git+https://github.com/johnwheeler/flask-ask.git@v0.8.8

pip install flask-ask




#Enjoy

Tuesday, December 10, 2019

Python Google Speech Setup and Example (WINDOWS)

1. Download SOX latest version - https://sourceforge.net/projects/sox/files/sox/

2. Install it (ex: C:\Program Files (x86)\sox-14-4-2 )
     2.1 download 2 (libmad-0.dll, libmp3lame-0.dll) DLLs and copy to C:\Program Files (x86)\sox-14-4-2;

                 https://app.box.com/s/tzn5ohyh90viedu3u90w2l2pmp2bl41t


3. Set environment path in system variable

4. Restart the IDE or CMD prompt

5. in cmd prompt
        set path=%path%;C:\Program Files (x86)\sox-14-4-2;
       echo %path%

6. pip install google_speech
    pip install sox

7. create a sample test.py


from google_speech import Speech

# say "Hello World"
text = "Hello This is Vijay DR";
lang = "en";
speech = Speech(text, lang);
speech.play();

# you can also apply audio effects while playing (using SoX)
# see http://sox.sourceforge.net/sox.html#EFFECTS for full effect documentation
sox_effects = ("speed", "1.5");
speech.play(sox_effects);

# save the speech to an MP3 file (no effect is applied)
speech.save("output.mp3");


8. cmp prompt py test.py



enjoy !
vijay

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}}}



Tuesday, September 24, 2019

Python - Map Nested Map

Input

[{
"groupId": "a1",
"orderId": "b1"
}, {
"groupId": "a2",
"orderId": "b2"
}, {
"groupId": "a2",
"orderId": "b3"
}]

Output 
{
'a1': {
'b1': {
'groupId': 'a1',
'orderId': 'b1'
}
},
'a2': {
'b2': {
'groupId': 'a2',
'orderId': 'b2'
},
'b3': {
'groupId': 'a2',
'orderId': 'b3'
}
}
}


Code

data = [{"groupId":"a1","orderId":"b1"},{"groupId":"a2","orderId":"b2"}, {"groupId":"a2","orderId":"b3"}]

groupMap = {}


for x in data:
    if ( helpers.isKeyExists (groupMap, x['groupId']) == False ):
        orderMap = {}
        orderMap[x['orderId']] = x;
        groupMap[x['groupId']] = orderMap;
    else:
        tempOrderMap = {}
        #if ( helpers.isKeyExists (orderMap, x['groupId']) == False ):
        tempOrderMap = groupMap[x['groupId']]
        tempOrderMap[x['orderId']] = x;
        groupMap[x['groupId']] = tempOrderMap;
       

print (groupMap);


Tuesday, September 17, 2019

Excel VBA - Loading POST REST Webservice JSON

1. Open excel -> developer -> visual basic
2. Tools -> reference (enabled : Microsoft win http services , version 5.1 xx )
3. paste the below code on click sheet1.
4. Click run.
5. Save As excel macro enabled from file type . else your VBA code will not be save.


Dim strResult As String
Dim objHTTP As Object
Dim URL As String
  
Private Sub Worksheet_Activate()
    Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
    
    json_body = "{'Commodity':'CRUDEOIL','Expiry':'17SEP2019'}"
    URL = "https://www.mcxindia.com/backpage.aspx/GetOptionChain"
    
    objHTTP.Open "POST", URL, False
    objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
    objHTTP.SetRequestHeader "Content-type", "application/json"
    objHTTP.Send (json_body)
    strResult = objHTTP.ResponseText
    Worksheets("Sheet1").Range("A10:A10") = strResult
    
End Sub




Friday, August 30, 2019

Python Schedule at every specific Time Interval

1. Install schedule plugin
2. use the below sample

schedulers.py

# Schedule Library imported
import schedule
import time
import datetime

def doScheduler ():
    print ( "Schedule starts @ ", datetime.datetime.now() );

# Task scheduling
# After every 10mins doScheduler () is called. 
schedule.every(10).minutes.do(doScheduler )
  
# After every hour doScheduler () is called.
schedule.every().hour.do(doScheduler )
  
# Every day at 12am or 00:00 time doScheduler () is called.
schedule.every().day.at("00:00").do(doScheduler )
  
# After every 5 to 10mins in between run doScheduler ()
schedule.every(5).to(10).minutes.do(doScheduler )
  
# Every monday doScheduler () is called
schedule.every().monday.do(doScheduler )
  
# Every tuesday at 18:00 doScheduler () is called
schedule.every().tuesday.at("18:00").do(doScheduler )

if __name__ == "__main__": schedule.every( 3 ).minutes.do( doScheduler )   
# Loop so that the scheduling task
# keeps on running all time.
while True:
  
     # Checks whether a scheduled task 
     # is pending to run or not
     schedule.run_pending()
     time.sleep(1)



#Enjoy !

Python Code to pull NSE Option Derivative HTML to JSON on Every N minutes

1. Install Python, PIP
2. type the below command from your python sample folder [ by pip or pip3 cmd ].
     pip install beautifulsoup
     OR
     pip install BeautifulSoup4
     pip install requests
     pip install schedule
     python nse_options.py

-- ENJOY

nse_options.py

# author - dr. vijay
# email - drvijayy2k2@gmail.com
# date - 30-08-2019 7:30 PM

# install plugin
# pip install BeautifulSoup

import sys
import json
import requests
# Schedule Library imported
import schedule
import time
import datetime

from bs4 import BeautifulSoup

base_url = 'https://www.nseindia.com/live_market/dynaContent/live_watch/option_chain/optionKeys.jsp?symbol=';


def doScheduler ():
    print ( "Schedule starts @ ", datetime.datetime.now() );
    result = parseNseOptions ( 'NIFTY' );
    # result = parseNseOptions ( 'INFY' );
    f = open( 'D:/nseOptionst.txt', 'a' )
    f.write( str(result) + "\n" );
    print ( "Done !" );
 

def parseNseOptions ( scrip='NIFTY' ):
    url = base_url + scrip;
    response = response = requests.get( url ) 
    if( response != None and response.ok ):
        optionScripListHtml = response.content
        # print ( optionScripListHtml );
        soup = BeautifulSoup( optionScripListHtml, "html.parser" )
        tableHtml = soup.find( "table", id="octable" )
        f1 = tableHtml.findAll( "thead" )[0].findAll( 'tr' )
     
        callDataColumnEndsAt = 11
        optionStrikePriceColumnAt = ( 12 - 1 )
        putDataColumnEndsAt = 23
        headers = {}
        headersOnIndex = {}
        h1 = f1[1].findAll( "th" )
        for index, h in enumerate( h1, start=0 ):
            if ( index < callDataColumnEndsAt ):
                headers["call-" + h.text] = h.get( "title", "" )
                headersOnIndex[index] = "call-" + h.text 
            elif ( index == optionStrikePriceColumnAt ):
                 headers[h.text] = h.get( "title", "" )
                 headersOnIndex[index] = h.text 
            elif ( index < putDataColumnEndsAt ):
                headers["put-" + h.text] = h.get( "title", "" )
                headersOnIndex[index] = "put-" + h.text 
        # print(headersOnIndex)
     
        fnoDataRows = tableHtml.findAll( "tr" )
        tempMap = {}
        totalOptionPCOI = {}
        tempMapWithStrikePriceAsKey = {}
        startingRow = 3
        endingRow = len( fnoDataRows )
        callOIChangeCol = 2
        callTotalChangeInOIValue = 0
        putOIChangeCol = 20
        putTotalChangeInOIValue = 0
        index = 1
        colIndex = 1
        recordFound = False
     
        for rowIndex, x in enumerate( fnoDataRows, start=0 ):
            if ( rowIndex == endingRow - 1 ):
                xx = x.findAll( "td" )
                totalOptionPCOI = {"callTotalOI": xx[1].text, "callTotalChangeInOI": xx[2].text, "callTotalVolume": xx[3].text, "putTotalVolume": xx[5].text, "putTotalChangeInOI": xx[6].text, "putTotalOI": xx[7].text }
                # break the entire loop as we got all the information
                break;
            for colIndex, c in enumerate( x.findAll( "td" ), start=0 ):
                value = c.text.strip()
                if value == "" or value == "-":
                    value = "0"
                else:
                    value = value.replace( ",", "" )
             
                if ( colIndex == callOIChangeCol ):
                    callTotalChangeInOIValue = callTotalChangeInOIValue + int( value )
                if ( colIndex == putOIChangeCol ):
                    putTotalChangeInOIValue = putTotalChangeInOIValue + int( value )
                     
                tempMap[ headersOnIndex[colIndex]] = value
                recordFound = True
             
            if recordFound == True:
                tempMapWithStrikePriceAsKey[tempMap[headersOnIndex[optionStrikePriceColumnAt]]] = tempMap.copy()
                strikePrice = tempMap["Strike Price"]
                tempMap.clear()   

            recordFound = False
     
        return dict( { "resultFetchTime": datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), "totalOptionPCOI":totalOptionPCOI, "mapWithStrikePriceAsKey":tempMapWithStrikePriceAsKey} )


if __name__ == "__main__":
 
    schedule.every( 3 ).minutes.do( doScheduler )
    while True:
        schedule.run_pending()
        time.sleep( 1 )


OUTPUT

{
'mapWithStrikePriceAsKey': {
//..... other strike prices
'10850.00': {
'call-Chart': '0',
'call-OI': '49950',
'call-Chng in OI': '26475',
'call-Volume': '10689',
'call-IV': '14.71',
'call-LTP': '210.75',
'call-Net Chng': '29.00',
'call-BidQty': '300',
'call-BidPrice': '208.85',
'call-AskPrice': '215.95',
'call-AskQty': '75',
'Strike Price': '10850.00',
'put-BidQty': '300',
'put-BidPrice': '19.50',
'put-AskPrice': '20.45',
'put-AskQty': '600',
'put-Net Chng': '-25.55',
'put-LTP': '20.45',
'put-IV': '14.92',
'put-Volume': '134223',
'put-Chng in OI': '261600',
'put-OI': '399750',
'put-Chart': '0'
},
'10900.00': {
'call-Chart': '0',
'call-OI': '574650',
'call-Chng in OI': '198600',
'call-Volume': '157457',
'call-IV': '14.15',
'call-LTP': '169.05',
'call-Net Chng': '26.85',
'call-BidQty': '4350',
'call-BidPrice': '169.05',
'call-AskPrice': '170.85',
'call-AskQty': '75',
'Strike Price': '10900.00',
'put-BidQty': '150',
'put-BidPrice': '27.45',
'put-AskPrice': '28.20',
'put-AskQty': '525',
'put-Net Chng': '-33.60',
'put-LTP': '28.20',
'put-IV': '14.22',
'put-Volume': '396350',
'put-Chng in OI': '894450',
'put-OI': '1796100',
'put-Chart': '0'
}
  //..... other strike prices
},
'totalOptionPCOI': {
'callTotalOI': ' 12,057,225',
'callTotalChangeInOI': '',
'callTotalVolume': ' 2,231,841',
'putTotalVolume': ' 1,883,484',
'putTotalChangeInOI': '',
'putTotalOI': ' 12,479,775'
}

}

Hit Counter


View My Stats