An introduce to xlsxwriter :)

xlsxwriter is an xlsx auto generate with charts in python

Today i will show how to generate the xlsx and send to reporter!

I am a maintainer and the server status must be reported to my boss every weekend . They prefer xlsx file and charts in the file.

So , i have to generate the xlsx with chart includ the summary of server status data .

finally , i will send it via my yandex mail to my boss.:)


Python raw tcp data convert to int

Today i will talk about the python built-in function ord() .

For example, I receive raw data from serial or tcp device,the data always be the array of binary.When you print it to console,it shows like b’\x01\xe5′ and so on.

To convert this data to int like below.

raw_data = b'\x01\xe5'

Thats it! very simple!OK thanks for reading see you soon!

Get player data and match via PUBG API

The programmer who do not know data analyze is not a good player in PUBG. 🙂

I will show some tool method below

# this function get the player data by PUBG player name and return the json data

def get_player_data(name):
    headers = {
        "Authorization": "Bearer {}".format(PUBG_API_TOKEN),
        "Accept": "application/vnd.api+json",
    payload = {"filter[playerNames]": name}

    result = requests.get("", params=payload,headers=headers)
    return result.json()
# this function get the match data by match id and return the match data json
def get_matches_by_id(id):
    headers = {
        "Accept": "application/vnd.api+json",

    result = requests.get("{}".format(id),headers=headers)
    return result.json()

This post just show the tool function . The next post will show how to use it and extract data!

Use PyPDF2 to extract the PDF annotation


I use Foxit PDF reader to read PDF books and well as take some marks and comments in the PDF file.But the PDF reader do not provide the export function,maybe i can find the entry for the function..:)

So I try to use PyPDF to export the comment I written in PDF

The Code:

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from PyPDF2 import PdfFileReader
import types
def text_extractor(path,output_path):
    text_file = open(output_path,'w')

    with open(path, 'rb') as f:
        pdf = PdfFileReader(f)
        # get the 4 page start from 0
        page = pdf.getPage(4)
        # write the raw text in to file
        contents = page.extractText()
        # print you comment/annotation text to console
        annotations = page.get("/Annots").getObject()
        for annot in annotations:
                if annot is not None:
                        if annot.getObject().get("/Contents") is not None:
                        # .get("/Highlight").getObject())

if __name__ == '__main__':
    path = './youPDF.pdf'
    out_path = './test.txt'


When you fill you PDF filename and path ,and run the script . the raw test will save in test.txt file.You comments will show in the console.But the code show above,just process page 4.If you want to export all you comment.You must add a for loop to iterate all pages and extract the text!