Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Forec/0001/0001.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# coding = utf-8
__author__ = 'forec'
import random

def make_number( num, length ):
str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
b = set()
i = 0
while i < num:
ans = ''
for j in range(length):
ans += random.choice(str)
if ans not in b:
b |= {ans}
i += 1
print(ans)

make_number( 200, 10)
46 changes: 46 additions & 0 deletions Forec/0002/0002.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# coding = utf-8
__author__ = 'Forec'

# 保随机码至MySQL

import pymysql
import random

def make_number( num, length ):
letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
dic = set()
i = 0
while i < num:
str = ''
for j in range(length):
str += random.choice(letters)
if str not in dic:
dic |= {str}
i += 1
else:
continue
return dic

def save( dic ):
connect = pymysql.connect(
host = '127.0.0.1',
port = 3306,
user = 'root',
passwd = 'VKDARK'
)
cur = connect.cursor()
try:
__create = 'create database if not exists test'
cur.execute(__create)
except:
print('database create error')
connect.select_db('test')
__create_table = 'create table if not exists codes(code char(64))'
cur.execute(__create_table)
cur.executemany('insert into codes values(%s)',dic)

connect.commit()
cur.close()
connect.close()

save(make_number(200,10))
19 changes: 19 additions & 0 deletions Forec/0004/0004.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import re
with open('input.txt',"r") as f:
data = f.read()

words = re.compile(r'([a-zA-Z]+)')
dic = {}
for x in words.findall(data):
if x not in dic:
dic[x] = 1
else:
dic[x] += 1
L = []
for k,value in dic.items():
L.append((k, value))

L.sort(key = lambda t:t[0])

for x in L:
print( x[0], x[1])
12 changes: 12 additions & 0 deletions Forec/0005/0005.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from PIL import Image, ImageOps
import os, os.path

L = [ x for x in os.listdir('.') if os.path.isfile(x) and os.path.splitext(x)[1]=='.jpg' ]

for x in L:
img = Image.open(x)
xsize, ysize = img.size
xsize = 500
ysize = ysize * 500 // xsize
img = ImageOps.fit(img,(xsize,ysize))
img.save("out"+x)
27 changes: 27 additions & 0 deletions Forec/0006/0006.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# coding = utf-8
__author__ = 'Forec'
import os, re

def find_word(file_path):
file_list = os.listdir(file_path)
word_dic = {}
word_re = re.compile(r'[\w]+')
for x in file_list:
if os.path.isfile(x) and os.path.splitext(x)[1] =='.txt' :
try:
f = open(x, 'r')
data = f.read()
f.close()
words = word_re.findall(data)
for word in words:
if word not in word_dic:
word_dic[word] = 1
else:
word_dic[word] += 1
except:
print('Open %s Error' % x)
Ans_List = sorted(word_dic.items(), key = lambda t : t[1], reverse = True)
for key, value in Ans_List:
print( 'Word ', key, 'appears %d times' % value )

find_word('.')
60 changes: 60 additions & 0 deletions Forec/0007/0007.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# coding = utf-8
# Can detect .py / .c / .cpp
__author__ = 'Forec'
import os
import re

def get_line( file_path ):
file_dir = os.listdir(file_path)
code ,exp ,space ,alls = ( 0, 0 ,0 , 0)
cFlag = True
exp_re = re.compile(r'[\"\'].*?[\"\']')
for x in file_dir:
if os.path.isfile(x) and (
os.path.splitext(x)[1] == '.py'
or os.path.splitext(x)[1] == '.c'
or os.path.splitext(x)[1] == '.cpp'
):
try:
f = open( x, 'r' )
except:
print('Cannot open file %s' % x)
for line in f.readlines():
alls += 1
if line.strip() == '' and cFlag:
space += 1
continue
find_exp = exp_re.findall(line)
for strs in find_exp:
line = line.replace(strs,'')
if os.path.splitext(x)[1] == '.py':
if '#' in line:
exp += 1
else :
code += 1
elif os.path.splitext(x)[1] == '.c' or os.path.splitext(x)[1] == '.cpp':
if r'*/' in line:
cFlag = True
exp += 1
elif r'/*' in line:
cFlag = False
exp += 1
elif not cFlag:
exp += 1
elif r'//' in line:
exp += 1
else:
code += 1
cFlag = True
try:
f.close()
except:
pass

print( '''All Lines total : %d
Codes total : %d
Spaces total: %d
Explanation : %d'''
% ( alls, code, space, exp ))

get_line('.')
14 changes: 14 additions & 0 deletions Forec/0009/0009.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#coding = utf-8
__author__ = 'Forec'

import requests
import re
from bs4 import BeautifulSoup

url = input()
html = requests.get(url)

soup = BeautifulSoup(html.text,"html.parser")
find_href = soup.findAll('a')
for x in find_href:
print(x['href'])