星星博客 »  > 

2021-05-06

import requests
import re
import os
import csv
url = ‘https://www.tiobe.com/tiobe-index/’
f = open(‘programming.csv’, ‘w’, newline=’’)
writer = csv.DictWriter(f, [‘Programming’,‘Percent’,‘Date’])
writer.writeheader()
response = requests.get(url, )
html = response.text
result = ‘’.join(re.findall(r’series: (.?)});’, html, re.DOTALL))
result = re.findall(r’({.
?})’, result, re.DOTALL)
for item in result:
name =’’.join(re.findall(r"{name : ‘(.?)’", item, re.DOTALL))
data = re.findall(r"[Date.UTC(.
?)]", item, re.DOTALL)
print(name)
for i in data:
i = i.replace(’ ‘, ‘’)
i = re.sub(r’[()]’, ‘’, i)
value = i.split(’,’)[-1]
time_list = i.split(’,’)[:3]
time = “”
for index, j in enumerate(time_list):
if index !=0:
if len(j) == 1:
j = ‘0’ + j
if index == 0:
time += j
else:
time += ‘-’ + j
temp = {
‘Programming’: name,
‘Percent’: value,
‘Date’: time
}
writer.writerow(temp)
f.close()

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from IPython.display import HTML

df = pd.read_csv(‘programming.csv’)

colors=dict(zip([‘C’,‘Python’,‘Java’,‘C++’,‘C#’,‘Visual Basic’,‘JavaScript’,‘Assembly language’,‘PHP’,‘SQL’],
[’#adb0ff’,’#ffb3ff’,’#90d595’,’#e48381’,’#aafbff’,’#f7bb5f’,’#eafb50’,’#23ffab’,’#abff12’,’#afbb90’]))
current_date=‘2021-04-02’
def draw_barchart(date):
dff=(df[df[‘Date’].eq(current_date)].sort_values(by=‘Percent’,ascending=True).head(10))
fig,ax=plt.subplots(figsize=(15,8))
ax.barh(dff[‘Programming’],dff[‘Percent’],color=[colors[x] for x in dff[‘Programming’]])
ax.text(1,0.4,current_date,transform=ax.transAxes,size=46,ha=‘right’)

draw_barchart(current_date)

animator=animation.FuncAnimation(fig,draw_barchart,frames=[‘2021-02-01’,‘2021-04-02’])
HTML(animator.to_jshtml())

相关文章