Python-master,实用Python脚本合集!

简介: Python-master,实用Python脚本合集!

1、创建二维码

import pyqrcode
import png
from pyqrcode import QRCode
# Text which is to be converted to QR code
print("Enter text to convert")
s = input(": ")
# Name of QR code png file
print("Enter image name to save")
n = input(": ")
# Adding extension as .pnf
d = n + ".png"
# Creating QR code
url = pyqrcode.create(s)
# Saving QR code as  a png file
url.show()
url.png(d, scale=6)

2、从图片中截取文字

# extract text from a img and its coordinates using the pytesseract module
import cv2
import pytesseract
# You need to add tesseract binary dependency to system variable for this to work
img = cv2.imread("img.png")
# We need to convert the img into RGB format
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
hI, wI, k = img.shape
print(pytesseract.image_to_string(img))
boxes = pytesseract.image_to_boxes(img)
for b in boxes.splitlines():
    b = b.split(" ")
    x, y, w, h = int(b[1]), int(b[2]), int(b[3]), int(b[4])
    cv2.rectangle(img, (x, hI - y), (w, hI - h), (0, 0, 255), 0.2)
cv2.imshow("img", img)
cv2.waitKey(0)

3、判断闰年

def is_leap(year):
    leap = False
    if year % 4 == 0:
        leap = True
        if year % 100 == 0:
            leap = False
            if year % 400 == 0:
                leap = True
    return leap
year = int(input("Enter the year here: "))
print(is_leap(year))

4、简易日历

from tkinter import *
import calendar
root = Tk()
# root.geometry("400x300")
root.title("Calendar")
# Function
def text():
    month_int = int(month.get())
    year_int = int(year.get())
    cal = calendar.month(year_int, month_int)
    textfield.delete(0.0, END)
    textfield.insert(INSERT, cal)
# Creating Labels
label1 = Label(root, text="Month:")
label1.grid(row=0, column=0)
label2 = Label(root, text="Year:")
label2.grid(row=0, column=1)
# Creating spinbox
month = Spinbox(root, from_=1, to=12, width=8)
month.grid(row=1, column=0, padx=5)
year = Spinbox(root, from_=2000, to=2100, width=10)
year.grid(row=1, column=1, padx=10)
# Creating Button
button = Button(root, text="Go", command=text)
button.grid(row=1, column=2, padx=10)
# Creating Textfield
textfield = Text(root, width=25, height=10, fg="red")
textfield.grid(row=2, columnspan=2)
root.mainloop()

5、打印图片分辨率

def jpeg_res(filename):
   """"This function prints the resolution of the jpeg image file passed into it"""
   # open image for reading in binary mode
   with open(filename,'rb') as img_file:
       # height of image (in 2 bytes) is at 164th position
       img_file.seek(163)
       # read the 2 bytes
       a = img_file.read(2)
       # calculate height
       height = (a[0] << 8) + a[1]
       # next 2 bytes is width
       a = img_file.read(2)
       # calculate width
       width = (a[0] << 8) + a[1]
   print("The resolution of the image is",width,"x",height)
jpeg_res("img1.jpg")
目录
相关文章
|
30天前
|
JSON 缓存 API
深度分析淘宝API接口,用Python脚本实现
本内容深入解析淘宝开放平台 API 的接口设计与 Python 实现,涵盖接口体系、认证机制、签名规则及限流策略,并提供完整的 Python 调用框架,适用于电商系统对接与自动化运营。
|
21天前
|
JSON 算法 API
深度分析小红书城API接口,用Python脚本实现
小红书作为以UGC内容为核心的生活方式平台,其非官方API主要通过移动端抓包解析获得,涵盖内容推荐、搜索、笔记详情、用户信息和互动操作等功能。本文分析了其接口体系、认证机制及请求规范,并提供基于Python的调用框架,涉及签名生成、登录态管理与数据解析。需注意非官方接口存在稳定性与合规风险,使用时应遵守平台协议及法律法规。
|
29天前
|
JSON API 数据安全/隐私保护
【干货满满】分享微店API接口到手价,用python脚本实现
微店作为知名社交电商平台,其开放平台提供商品查询、订单管理等API接口。本文介绍如何通过微店API获取商品到手价(含优惠、券等),涵盖认证机制、Python实现及关键说明。
|
29天前
|
JSON API 数据安全/隐私保护
【干货满满】分享淘宝API接口到手价,用python脚本实现
淘宝开放平台通过API可获取商品到手价,结合商品详情与联盟接口实现优惠计算。需使用AppKey、AppSecret及会话密钥认证,调用taobao.tbk.item.info.get接口获取最终价格。代码示例展示签名生成与数据解析流程。
|
30天前
|
JSON API 数据安全/隐私保护
深度分析苏宁API接口,用Python脚本实现
苏宁易购开放平台提供覆盖商品、订单、库存、门店等零售全链路的API服务,采用RESTful架构与“AppKey+AppSecret+签名”认证机制,支持线上线下一体化业务处理。本文详解其API特性、认证流程及Python调用实现。
|
30天前
|
自然语言处理 安全 API
深度分析洋码头API接口,用Python脚本实现
洋码头是国内知名跨境电商平台,专注于海外商品直购。本文基于其API的通用设计逻辑,深入解析了认证机制、签名规则及核心接口功能,并提供了Python调用示例,适用于商品与订单管理场景。
|
30天前
|
JSON API 数据格式
深度分析易贝API接口,用Python脚本实现
本文深度解析了eBay开放平台的RESTful API接口体系,涵盖其核心功能、OAuth 2.0认证机制、请求规范及限流策略,并基于Python构建了完整的API调用框架。内容包括商品与订单管理接口的实现逻辑、认证流程、错误处理机制及实战调用示例,适用于跨境电商系统开发与多平台集成。
|
30天前
|
JSON 监控 BI
深度分析亚马逊API接口,用Python脚本实现
本内容深度解析亚马逊SP-API接口体系,涵盖商品、订单、库存等核心功能域,详解LWA认证、AWS签名及Python调用实现,适用于跨境电商系统开发与集成。
|
30天前
|
API Python 数据格式
深度分析京东API接口,用Python脚本实现
深度分析京东API接口,用Python脚本实现
|
1月前
|
JSON API 开发者
深度分析微店API接口,用Python脚本实现
微店作为知名移动端电商平台,其开放平台提供丰富的API接口,支持商品、订单、客户及营销管理。本文分析其API核心特性,并提供Python调用示例,助力开发者快速集成业务功能。

热门文章

最新文章

推荐镜像

更多