Skip to main content

Posts

Showing posts from October, 2019

youtube-dl download using python in a specific folder and of a particular quality

import  subprocess import  tempfile import  os import  youtube_dl import  time class   MyLogger ( object ):      def   debug ( self ,  msg ):          pass      def   warning ( self ,  msg ):          pass      def   error ( self ,  msg ):          print (msg) def   my_hook ( d ):      if  d[ 'status' ] ==  'finished' :          print ( 'Done downloading, now converting ...' ) ydl_opts = {           'outtmpl' :  './temp/ZCL5.mp4' ,      'logger' : MyLogger(),      'progress_hooks' : [my_hook],      'format' :  'worst' } with  youtube_dl.YoutubeDL(ydl_opts)  as  ydl:     starttime = time.time()     ydl.download([ 'https://www.youtube.com/watch?v=sHAkDTlv8fA' ])     completeTime = time.time()      print (completeTime - starttime)              print ( "printing file in temp dir" ) basepath = tempfile.gettempdir() for  entry  in  os.

asyncio concurrent task in loop in python 3.7

import asyncio import time async def say_after(delay, what):     print(f"Req time at {time.strftime('%X')} for "+ what)     await asyncio.sleep(delay)     # print(what)     print(f"Return time at {time.strftime('%X')} for "+ what + " delay = "+ str(delay))     return ("hero , delay = " + str(delay)+ " value = "+ what ) async def main():     # task1 = asyncio.create_task(     #     say_after(1, 'hello'))     #     # task2 = asyncio.create_task(     #     say_after(2, 'world'))     print(f"started at {time.strftime('%X')}")     tasks = []     loop: AbstractEventLoop = asyncio.get_event_loop()     for i in range(5):         tasks.append(asyncio.create_task(         say_after(i+1, 'pila')         ))         # print( val + "")     for task in tasks:         # print( await task)         print(await task)     # Wait until both tasks are completed

multiprocessing with asyncio in python sample program

import asyncio import time async def say_after(delay, what):     await asyncio.sleep(delay)     print(what)     return ("hero" + str(delay)) async def main():     task1 = asyncio.create_task(         say_after(1, 'hello'))     task2 = asyncio.create_task(         say_after(2, 'world'))     print(f"started at {time.strftime('%X')}")     # Wait until both tasks are completed (should take     # around 2 seconds.)     print(await task1)     print(await task2)     print(f"finished at {time.strftime('%X')}") asyncio.run(main())

highlight text in elasticsearch result

Example PUT test_index/_doc/doc1 {   "content" : "For you I'm only a fox like a hundred thousand other foxes. But if you tame me, we'll need each other. You'll be the only boy in the world for me. I'll be the only fox in the world for you." } GET test_index/_search {     "query": {         "match_phrase" : {"content" : "only fox"}     },     "highlight": {         "type" : "unified",         "number_of_fragments" : 3,         "fields": {             "content": {}         }     } } ---------------------- for deepdive "highlight": {     "fields": {       "script": {}     }   }