lalala

import subprocess
from datetime import datetime
import time
import os
import string
import random


def run_command(command):
output1 = subprocess.run(command, capture_output=True, text=True)

# Execute multiple commands in sequence and capture their output
print(output1.stdout)


def random_modify_file(path='.'):
# 获取目录下所有不包含自身的文件
files = []
for f in os.listdir(path):
if os.path.isfile(f) and f != os.path.basename(os.path.realpath(__file__)):
files.append(f)
# 随机选择一个文件
random_file = random.choice(files)
# 打开文件并读取内容
with open(random_file, 'w') as file:
# Generate random content and write it to the file
content = str(random.randint(1, 100)) + '\n'
file.write(content)
print("{} is changed!".format(random_file))

def random_new_file():
letters_digits = string.ascii_lowercase + string.digits
filename = ''.join(random.choice(letters_digits) for i in range(6))
# Returning the filename with a .txt extension
filename = filename + '.txt'
with open(filename, 'w') as file:
pass
print("{} was generated!".format(filename))

def main():

while 1:
if datetime.now().hour == 17:
# 拉取代码

# 修改文件内容
# 1. 随机新建文件
# 2. 随机修改已有文件
random.choice([random_new_file, random_modify_file])()

# 提交代码
# Add all changes to the staging area
run_command(['git', 'add', '.'])

# Commit changes with a commit message
run_command(['git', 'commit', '-m', 'fixed'])

# Push changes to the remote repository
run_command(['git', 'push'])
print("auto push code completed!")
rt = random.randint(1, 60)
time.sleep(25*rt)


main()
posted @ 2023-04-06 14:19  liown  阅读(27)  评论(0编辑  收藏  举报