如今,网上的资源很多,好东西少,免费的少,免费的好东西,少之又少。
如果你想利用碎片时间,学点技能。现实总是很残酷,网上的东西很少,都是抄来抄去的。很多公众号,不是广告就是软文,还有搞知识星球的,花点钱,也不一定买到好东西。
当付费都得不到好内容时,免费就更加不用说了。
我这里总结出了一些免费获取好东西的方法。 当然你得对技术有兴趣,有想法,对啃代码有热情。
第一个,就是站在巨人的肩膀上。当然我们可能不是站在巨人的肩膀,我们可以站在别人的肩膀。 我们可以读各种框架的源码,优秀的源码可以给我们启发。 比如这个: 这个是webdriver里面的wait until 和wait until not
def until(self, method, message=''):
"""Calls the method provided with the driver as an argument until the \
return value is not False."""
screen = None
stacktrace = None
end_time = time.time() + self._timeout
while True:
try:
value = method(self._driver)
if value:
return value
except self._ignored_exceptions as exc:
screen = getattr(exc, 'screen', None)
stacktrace = getattr(exc, 'stacktrace', None)
time.sleep(self._poll)
if time.time() > end_time:
break
raise TimeoutException(message, screen, stacktrace)
def until_not(self, method, message=''):
"""Calls the method provided with the driver as an argument until the \
return value is False."""
end_time = time.time() + self._timeout
while True:
try:
value = method(self._driver)
if not value:
return value
except self._ignored_exceptions:
return True
time.sleep(self._poll)
if time.time() > end_time:
break
raise TimeoutException(message)
我们可以改造成自己的轮子,直接作为装饰器
import time
timeout = 3
poll =1
class TimeoutException(Exception):
"this is user's Exception for timeout"
def __init__(self,message,screen=None,staktrace=None):
self.message = message
self.screen = screen
self.staktrace = staktrace
def __str__(self):
print(self.message)
if self.screen:
print(self.screen)
if self.staktrace:
print(self.staktrace)
def ignored_exceptions(Exception):
pass
def wait_until(message=''):
def warper(method):
def until(*args, **kwargs):
print(message)
screen = None
stacktrace = None
end_time = time.time() + timeout
while True:
try:
value = method(*args, **kwargs)
if value:
return value
except ignored_exceptions as exc:
screen = getattr(exc, 'screen', None)
stacktrace = getattr(exc, 'stacktrace', None)
time.sleep(poll)
if time.time() > end_time:
break
raise TimeoutException(message, screen, stacktrace)
return until
return warper
def wait_until_not(message=''):
def warper(method):
def until_not(*args, **kwargs):
end_time = time.time() + timeout
while True:
try:
value = method(*args, **kwargs)
if not value:
return value
except ignored_exceptions:
return True
time.sleep(poll)
if time.time() > end_time:
break
raise TimeoutException(message)
return until_not
return warper
@wait_until(message="do not kick out")
def add_some(a,b):
print(a)
c = a+b
print(c)
return c
if __name__ == "__main__":
d = add_some(120,210)
print(d)
这样,我们需要执行任何需要等待的操作,都可以套上这个。
站在别人的肩膀第二招: 大家都知道全球最大的同性交友网站,github, 上面有很多好的源码,我们直接可以捞来看。看看别人都在用各种语言做什么。 我们可以用一个爬虫,将某种语言别人提交的最新代码列表弄下来,看看哪个符合自己的口味。
我这里用很简单的代码,就实现了
import pandas as pd
git_url = "https://www.github.com/github/"
page_result = pd.read_html(git_url)[0]
# print(page_result)
# print(page_result["语言"])
# print(page_result.loc[page_result["语言"] == "Python"])
file_name = "code.txt"
#
import os
my_path = os.path.split(os.path.realpath(__file__))[0]
my_file = my_path + "/" + file_name
print(my_file)
python_result = page_result.loc[page_result["语言"] == "Python"]
# sort_values has already replace sort
python_result.sort_values(["Star"],ascending=True)
# print(python_result)
#axis=1(按列方向操作)、inplace=True(修改完数据,在原数据上保存)
#按标签来删除列
python_result.drop(['语言'],axis=1,inplace=True)
python_result['名称']= "https://github.com/" + python_result['名称']
python_result.to_csv("code.txt",sep="\t")
#
import yagmail
#链接邮箱服务器
yag = yagmail.SMTP( user="username@163.com", password="password", host='smtp.163.com',smtp_ssl=True)
# 邮箱正文
contents = ['python code for github']
# 发送邮件
yag.send(to='snake@qq.com', subject='Read the code', contents=contents,attachments =my_file)
这里不局限于python, 如果你兴趣广泛,这里可以搜索各种语言,按照star的从高到低排列。 可以发到QQ邮箱,用这个QQ登陆微信,就可以在微信中看到了。这没有直接发微信消息,因为微信消息接收文字有限,而且很容易排列乱,不方便阅读。
可以集成在CI里面,定时发送。 当有邮件时,会有提醒:
打开邮箱
这样就可以阅读了
如果觉得还可以,在电脑上就可以将代码下载下来,仔细研究了。
当然这样也可以下载好的书籍,资讯,这样就可以充分利用好碎片时间来学习了。