Saturday, August 12, 2023

Writing a list of lists in an excel file using openpyxl

import openpyxl
work_book=openpyxl.Workbook()
work_sheet=work_book.active
data=[["Champion","Year"],
    ['Uruguay',    1930],
    ['Italy',    1934],
    ['Italy',    1938],
    ['Uruguay',    1950],
    ['Germany',    1954],
    ['Brazil',    1958],
    ['Brazil',    1962],
    ['England',    1966],
    ['Brazil',    1970],
    ['Germany',    1974],
    ['Argentina',1978],
    ['Italy',    1982],
    ['Argentina',1986],
    ['Germany',    1990],
    ['Brazil',    1994],
    ['France',    1998],
    ['Brazil',    2002],
    ['Italy',    2006],
    ['Spain',    2010],
    ['Germany',    2014],
    ['France',    2018],
    ['Argentina',2022]]

for r in data:
    work_sheet.append(r)


#save the work book

work_book.save(r'C:\Users\allso\Desktop\new vba projects\openpyxl\world_cup.xlsx')

Saturday, June 10, 2023

Freeze top row using Openpyxl

import openpyxl

#freeze and unfreeze using openpyxl
#open zomato spreadsheet

work_book=openpyxl.load_workbook(r'C:\Users\allso\Desktop\new vba projects\openpyxl\zomato.xlsx')


#select active sheet

sheet=work_book.active

#freeze the top row
#all rows above the current row and all columns left to the current column will be frozen

sheet.freeze_panes="A2"

#save the work book

work_book.save(r'C:\Users\allso\Desktop\new vba projects\openpyxl\zomato.xlsx')


Convert csv to xlsx as openpyxl does not support .csv file format


import csv
from openpyxl import Workbook

wb = Workbook()
ws = wb.worksheets[0]
ws.title = "zomato"

with open(r'C:\Users\allso\Desktop\new vba projects\openpyxl\zomato.csv',encoding='cp437', errors='ignore') as f:
    reader = csv.reader(f)
    for row_index, row in enumerate(reader):
        for column_index, cell in enumerate(row):
            column_letter = column_index + 1
            cell_value = cell.replace('"', '')
            ws.cell(row = row_index + 1, column = column_letter).value = cell_value



wb.save(filename = r'C:\Users\allso\Desktop\new vba projects\openpyxl\zomato.xlsx')


Saturday, May 6, 2023

vlsub not working solved

opensubtitles API has changed its request format from XML to JSON only. In adiction it also needs a session token to validate requests. So, in a few words, VLSub needs a re-work to replace the old function, to call the API with a valid token and process JSON data.

EDIT: But, there's a workarround for this. As the previous version of opensubtitles is still working, you can edit your system hosts file to route VLSub call as XML. The default path of the hosts file in Windows 10 appears to be C:\Windows\System32\drivers\etc and you have to open your text editor as admin to edit the file. Add a new line and type 104.25.132.104 api.opensubtitles.org Save hosts file and try VLSub again. NOTE: This is valid while XML service is active in the old API address.



Friday, April 7, 2023

Some common usages of cat command

1) To view a single file 
Command: 
 

$cat filename

Output 
 

It will show content of given filename

 

2) To view multiple files 
Command: 

 

 

$cat file1 file2

Output 
 

This will show the content of file1 and file2.

 

 

3) To view contents of a file preceding with line numbers. 
Command: 
 

$cat -n filename

Output 
 

It will show content with line number
example:-cat -n  geeks.txt
 
1)This is geeks
2)A unique array

 

4) Create a file 
Command: 
 

$ cat > newfile

Output 
 

Will create a file named newfile

 

5) Copy the contents of one file to another file. 
Command: 
 

$cat [filename-whose-contents-is-to-be-copied] > [destination-filename]

Output 
 

The content will be copied in destination file

 

6) Cat command can append the contents of one file to the end of another file. 
Command: 
 

$cat file1 >> file2

Output 
 

Will append the contents of one file to the end of another file
 

7) Cat command can display content in reverse order using tac command. 
Command: 
 

 $tac filename

Output 
 

Will display content in reverse order 
 

8) Cat command to merge the contents of multiple files. 
Command: 
 

$cat "filename1" "filename2" "filename3" > "merged_filename"

Output 
 

Will merge the contents of file in respective order and will insert that content in "merged_filename".
 
 
 

9) Cat command to display the content of all text files in the folder. 
Command: 
 

$cat *.txt

Output 
 

Will show the content of all text files present in the folder.
 

 

10) Cat command can suppress repeated empty lines in output 
Command: 
 

$cat -s geeks.txt

Output 

Will suppress repeated empty lines in output
 
 
Source:https://www.geeksforgeeks.org/cat-command-in-linux-with-examples/