diff --git a/Pacico/0000/0000.py b/Pacico/0000/0000.py new file mode 100644 index 00000000..047a8687 --- /dev/null +++ b/Pacico/0000/0000.py @@ -0,0 +1,27 @@ +# -*- coding:cp936 -*- +def imgaddingtext(filepath,text,fonttype='arial.ttf',color='black'): + from PIL import Image, ImageDraw, ImageFont + import os + img=Image.open(filepath) + x,y=img.size + draw=ImageDraw.Draw(img) + font=ImageFont.truetype(fonttype,(min(img.size))/5) + draw.text((x/2,y/2),text,fill=color,font=font) + img.save((os.path.dirname(filepath))+'\\''new.jpg') + +#设置变量的默认随机值 +import random +listfont=['arial.ttf'] +listcolor=['red','black','brown','white','pink','yellow'] +filepath=raw_input('enter exact path for you file(picture):') +text=raw_input('enter your text:') +fonttype=raw_input('enter the font:') +if fonttype not in listfont: + print 'The fonttype you choose does not exit' + fonttype=random.choice(listfont) +color=raw_input('enter the color:') +if color not in listcolor: + print 'The color you choose does not exit' + color=random.choice(listcolor) +imgaddingtext(filepath,text,fonttype,color) + diff --git a/Pacico/0000/readme.md b/Pacico/0000/readme.md new file mode 100644 index 00000000..05af7886 --- /dev/null +++ b/Pacico/0000/readme.md @@ -0,0 +1 @@ +将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。 类似于图中效果 diff --git a/Pacico/0001/0001.py b/Pacico/0001/0001.py new file mode 100644 index 00000000..a566495e --- /dev/null +++ b/Pacico/0001/0001.py @@ -0,0 +1,20 @@ +# -*- coding:cp936 -*- +import string +import random +import os +codelib=[] +for i in range(200): + code='' + num='' + for i in range(4): + k=random.choice(string.letters) + code=code+k + for i in range(8): + k =random.choice(range(10)) + num=str(k)+num + codelib.append(code+'-'+num) + +txt=open('F:\Trinick\Script\ShowMeTheCode\\002_code.txt','w') +for k in codelib: + txt.writelines(k+'\n') +txt.close() diff --git a/Pacico/0001/0001Code.txt b/Pacico/0001/0001Code.txt new file mode 100644 index 00000000..1e95a218 --- /dev/null +++ b/Pacico/0001/0001Code.txt @@ -0,0 +1,200 @@ +cxAA-23073429 +Dbsq-37465734 +CVMR-67077591 +xitF-37144231 +wglo-66025674 +dHnK-16380451 +ABXa-81783307 +LoLy-30845215 +XfbS-46371386 +BUBP-78510215 +dNbC-24942325 +iHJN-13385038 +rmWQ-94603183 +XoBY-28300078 +wkLf-84269092 +ZbsV-08615552 +pRMB-59171896 +JoRU-66103885 +inbF-44310861 +pouE-94541097 +MLTS-34818264 +UMNM-30229379 +Kwyr-45651926 +oDvN-36230642 +FThK-41478151 +JXCZ-58207108 +uNYm-86608662 +Wcqi-43218984 +ejen-28685467 +CKOt-65878451 +TVxo-08168113 +acZB-55510498 +RBAE-23761318 +IhxR-37235636 +hMgc-10951940 +fkJM-38679661 +NCQr-29204051 +VEgN-81583114 +vQyo-62569591 +rZaD-11333864 +nsnA-16908581 +LkIa-66591096 +vKsr-45010908 +UgGE-86743933 +HNxy-84547159 +IRph-35063715 +ZORi-84819132 +awTa-01694404 +ReCk-42483904 +ytJC-12029081 +RHum-66344764 +JRUK-60144436 +QtCP-42899509 +ZfZE-08514259 +vStP-92243658 +rUfz-91636753 +GLDH-66198531 +PHBI-07334441 +HfGD-78798607 +ezVY-63882704 +EYVJ-48525534 +YMNg-30323678 +UABL-02589713 +ygsR-29769863 +ICiD-47305175 +BOLH-57505956 +lGwl-95647647 +ciVK-47197719 +aBBg-97947450 +ctxY-21675798 +sXof-51217856 +vueB-86360700 +gbvU-25373415 +fXpD-06321202 +BHbw-02558280 +YgiW-55246107 +UqNE-63956116 +dxFW-59651793 +vKPv-11546356 +cyfk-80472685 +WYta-38018594 +DtvV-29030806 +JcaY-62283893 +KqFM-93779408 +rzCZ-22503874 +GWQV-45737798 +vqZG-45350465 +MbuN-85477425 +ASBT-31014002 +YLss-96176722 +reAA-38213950 +bycp-46440555 +BBvZ-15901747 +GtdG-05558384 +dgqk-27977549 +LRXA-16779379 +rjAD-40091761 +Jxay-15053561 +MPoN-93394757 +npVb-15559164 +udAP-79381916 +Btls-72907709 +xoSh-92958464 +vMnF-72889929 +Bwxu-82620432 +ukSt-65540578 +iOPE-80412798 +jpqB-16222478 +WRVN-15235518 +ugvK-47794013 +ZQvW-95885105 +ESUp-95700094 +JvDj-94020724 +hapu-83900721 +cfyY-03622917 +ooKM-93712475 +zbad-85943747 +iyFI-64495952 +VxTN-07210174 +QvIF-15578514 +NXDR-08298816 +qgUj-90054290 +dyYh-56862576 +mZXX-13996045 +Awdn-73638981 +iodG-70763760 +nvsY-10747960 +jxXd-96596541 +dLed-73802771 +VHtd-93441059 +wPxS-80474766 +pOJC-12554385 +ROYA-56869715 +INWY-89484492 +zAlk-11372544 +XJxZ-67219669 +ZZVc-19851568 +xQxG-78589653 +qcPv-88808780 +APXA-60369759 +LoyJ-88547562 +Ggib-59428409 +EaXW-94644924 +ZXyf-06853641 +ewad-63277495 +rJpn-54822871 +UyQH-16092173 +HBcY-62422296 +jFfk-43980704 +vFMq-55403564 +iWNR-66693691 +SLgk-43633172 +DsKd-12554818 +QiUx-72878286 +DErq-52668861 +oUOE-35302567 +VQzq-37997873 +BTji-71456681 +fXio-29711121 +tSEs-86912954 +Mpkt-98592453 +EpkH-20564804 +OGoB-63768433 +jQGG-21071430 +KXMZ-98117123 +OqCI-36206286 +NZvb-60573387 +wnHQ-59373900 +NCas-43976543 +ZawX-42632739 +ayAR-67950878 +GTWX-60680260 +CRDb-36760934 +LQGe-77372627 +XWoj-93451978 +WRla-57444369 +QfFO-95088405 +hHUJ-17195067 +GcrZ-77020690 +eAUf-48202460 +hqFu-19889253 +RfJj-77150914 +EMDf-98543135 +ISRN-51729308 +jexy-29803012 +INMl-08496654 +oNfx-21877304 +vwpu-81309941 +HMwg-16797410 +FooZ-21861723 +nHDt-28373571 +TFIu-26663138 +VBRs-46016828 +cqlc-95289152 +lPJS-74966764 +iPQz-94543017 +SFsO-04071474 +fGbg-52603928 +wOLJ-50003555 +jCNs-06214495 diff --git a/Pacico/0001/readme.md b/Pacico/0001/readme.md new file mode 100644 index 00000000..27d220bf --- /dev/null +++ b/Pacico/0001/readme.md @@ -0,0 +1 @@ +做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)? diff --git a/Pacico/0002/0002.py b/Pacico/0002/0002.py new file mode 100644 index 00000000..011562a9 --- /dev/null +++ b/Pacico/0002/0002.py @@ -0,0 +1,29 @@ +# -*-coding:cp936 -*- +import MySQLdb +con=MySQLdb.connect(user='root',passwd='root',host='127.0.0.1') +cur=con.cursor() +cur.execute('show databases;') +databases=cur.fetchall() +if ('showmethecode',) not in databases: + cur.execute('CREATE DATABASE showmethecode;') +con.select_db('showmethecode') +cur.execute('show tables;') +tables=cur.fetchall() +if ('appcode',) not in tables: + cur.execute(""" +CREATE TABLE appcode( +id INT NOT NULL AUTO_INCREMENT, +code VARCHAR(14) NOT NULL, +PRIMARY KEY (id)) +; +""") + +codefile=open('F:\Trinick\Script\ShowMeTheCode\\001_code.txt') +readcode=codefile.readlines() +for line in readcode: + cur.execute(""" +insert into appcode(code) value(%s); +""",[line]) +con.commit() +cur.close() +con.close() diff --git a/Pacico/0002/readme.md b/Pacico/0002/readme.md new file mode 100644 index 00000000..79481cec --- /dev/null +++ b/Pacico/0002/readme.md @@ -0,0 +1 @@ +将 0001 题生成的 200 个激活码(或者优惠券)保存到 MySQL 关系型数据库中 diff --git a/Pacico/0004/0004 b/Pacico/0004/0004 new file mode 100644 index 00000000..981942b3 --- /dev/null +++ b/Pacico/0004/0004 @@ -0,0 +1,16 @@ +# -*- coding: cp936 -*- + +def main(): + import re + txt = open(r"F:\Trinick\Script\ShowMeTheCode\\004Obamas'Speech.txt") + rp=r'[\W]\b[Ff]reedom' #确保counts 'freedom' only,排除 'unfreedom' 等情况 + con =txt.read() + matchs = re.findall(rp, con) + count = len(matchs) + txt.close() + return count + + +if __name__== '__main__': + main() + diff --git a/Pacico/0004/Obamas' Speech.txt b/Pacico/0004/Obamas' Speech.txt new file mode 100644 index 00000000..6be9e675 --- /dev/null +++ b/Pacico/0004/Obamas' Speech.txt @@ -0,0 +1,36 @@ +January 20,2009 +  My fellow citizens: +  I stand here today humbled by the task before us, grateful for the trust you have bestowed, mindful of the sacrifices borne by our ancestors. I thank President Bush for his service to our nation, as well as the generosity and cooperation he has shown throughout this transition. +  Forty-four Americans have now taken the presidential oath. The words have been spoken during rising tides of prosperity and the still waters of peace. Yet, every so often the oath is taken amidst gathering clouds and raging storms. At these moments, America has carried on not simply because of the skill or vision of those in high office, but because We the People have remained faithful to the ideals of our forbearers, and true to our founding documents. +  So it has been. So it must be with this generation of Americans. +  That we are in the midst of crisis is now well understood. Our nation is at war, against a far-reaching network of violence and hatred. Our economy is badly weakened, a consequence of greed and irresponsibility on the part of some, but also our collective failure to make hard choices and prepare the nation for a new age. Homes have been lost; jobs shed; businesses shuttered. Our health care is too costly; our schools fail too many; and each day brings further evidence that the ways we use energy strengthen our adversaries and threaten our planet. +  These are the indicators of crisis, subject to data and statistics. Less measurable but no less profound is a sapping of confidence across our land - a nagging fear that America’s decline is inevitable, and that the next generation must lower its sights. +  Today I say to you that the challenges we face are real. They are serious and they are many. They will not be met easily or in a short span of time. But know this, America - they will be met. +  On this day, we gather because we have chosen hope over fear, unity of purpose over conflict and discord. +  On this day, we come to proclaim an end to the petty grievances and false promises, the recriminations and worn out dogmas, that for far too long have strangled our politics. +  We remain a young nation, but in the words of Scripture, the time has come to set aside childish things. The time has come to reaffirm our enduring spirit; to choose our better history; to carry forward that precious gift, that noble idea, passed on from generation to generation: the God-given promise that all are equal, all are free, and all deserve a chance to pursue their full measure of happiness. +  In reaffirming the greatness of our nation, we understand that greatness is never a given. It must be earned. Our journey has never been one of short-cuts or settling for less. It has not been the path for the faint-hearted - for those who prefer leisure over work, or seek only the pleasures of riches and fame. Rather, it has been the risk-takers, the doers, the makers of things - some celebrated but more often men and women obscure in their labor, who have carried us up the long, rugged path towards prosperity and freedom. +  For us, they packed up their few worldly possessions and traveled across oceans in search of a new life. +  For us, they toiled in sweatshops and settled the West; endured the lash of the whip and plowed the hard earth. +  For us, they fought and died, in places like Concord and Gettysburg; Normandy and Khe Sanh. +  Time and again these men and women struggled and sacrificed and worked till their hands were raw so that we might live a better life. They saw America as bigger than the sum of our individual ambitions; greater than all the differences of birth or wealth or faction. +  This is the journey we continue today. We remain the most prosperous, powerful nation on Earth. Our workers are no less productive than when this crisis began. Our minds are no less inventive, our goods and services no less needed than they were last week or last month or last year. Our capacity remains undiminished. But our time of standing pat, of protecting narrow interests and putting off unpleasant decisions - that time has surely passed. Starting today, we must pick ourselves up, dust ourselves off, and begin again the work of remaking America. +  For everywhere we look, there is work to be done. The state of the economy calls for action, bold and swift, and we will act - not only to create new jobs, but to lay a new foundation for growth. We will build the roads and bridges, the electric grids and digital lines that feed our commerce and bind us together. We will restore science to its rightful place, and wield technology’s wonders to raise health care’s quality and lower its cost. We will harness the sun and the winds and the soil to fuel our cars and run our factories. And we will transform our schools and colleges and universities to meet the demands of a new age. All this we can do. And all this we will do. +  Now, there are some who question the scale of our ambitions - who suggest that our system cannot tolerate too many big plans. Their memories are short. For they have forgotten what this country has already done; what free men and women can achieve when imagination is joined to common purpose, and necessity to courage. +  What the cynics fail to understand is that the ground has shifted beneath them - that the stale political arguments that have consumed us for so long no longer apply. The question we ask today is not whether our government is too big or too small, but whether it works - whether it helps families find jobs at a decent wage, care they can afford, a retirement that is dignified. Where the answer is yes, we intend to move forward. Where the answer is no, programs will end. And those of us who manage the public’s dollars will be held to account - to spend wisely, reform bad habits, and do our business in the light of day - because only then can we restore the vital trust between a people and their government. +  Nor is the question before us whether the market is a force for good or ill. Its power to generate wealth and expand freedom is unmatched, but this crisis has reminded us that without a watchful eye, the market can spin out of control - and that a nation cannot prosper long when it favors only the prosperous. The success of our economy has always depended not just on the size of our Gross Domestic Product, but on the reach of our prosperity; on our ability to extend opportunity to every willing heart - not out of charity, but because it is the surest route to our common good. +  As for our common defense, we reject as false the choice between our safety and our ideals. Our Founding Fathers, faced with perils we can scarcely imagine, drafted a charter to assure the rule of law and the rights of man, a charter expanded by the blood of generations. Those ideals still light the world, and we will not give them up for expedience’s sake. And so to all other peoples and governments who are watching today, from the grandest capitals to the small village where my father was born: know that America is a friend of each nation and every man, woman, and child who seeks a future of peace and dignity, and that we are ready to lead once more. +  Recall that earlier generations faced down fascism not just with missiles and tanks, but with sturdy alliances and enduring convictions. They understood that our power alone cannot protect us, nor does it entitle us to do as we please. Instead, they knew that our power grows through its prudent use; our security emanates from the justness of our cause, the force of our example, the tempering qualities of humility and restraint. +  We are the keepers of this legacy. Guided by these principles once more, we can meet those new threats that demand even greater effort - even greater cooperation and understanding between nations. We will begin to responsibly leave Iraq to its people, and forge a hard-earned peace in Afghanistan. With old friends and former foes, we will work tirelessly to lessen the nuclear threat, and roll back the specter of a warming planet. We will not apologize for our way of life, nor will we waver in its defense, and for those who seek to advance their aims by inducing terror and slaughtering innocents, we say to you now that our spirit is stronger and cannot be broken; you cannot outlast us, and we will defeat you. +  For we know that our patchwork heritage is a strength, not a weakness. We are a nation of Christians and Muslims, Jews and Hindus - and non-believers. We are shaped by every language and culture, drawn from every end of this Earth; and because we have tasted the bitter swill of civil war and segregation, and emerged from that dark chapter stronger and more united, we cannot help but believe that the old hatreds shall someday pass; that the lines of tribe shall soon dissolve; that as the world grows smaller, our common humanity shall reveal itself; and that America must play its role in ushering in a new era of peace. +  To the Muslim world, we seek a new way forward, based on mutual interest and mutual respect. To those leaders around the globe who seek to sow conflict, or blame their society’s ills on the West - know that your people will judge you on what you can build, not what you destroy. To those who cling to power through corruption and deceit and the silencing of dissent, know that you are on the wrong side of history; but that we will extend a hand if you are willing to unclench your fist. +  To the people of poor nations, we pledge to work alongside you to make your farms flourish and let clean waters flow; to nourish starved bodies and feed hungry minds. And to those nations like ours that enjoy relative plenty, we say we can no longer afford indifference to suffering outside our borders; nor can we consume the world’s resources without regard to effect. For the world has changed, and we must change with it. +  As we consider the road that unfolds before us, we remember with humble gratitude those brave Americans who, at this very hour, patrol far-off deserts and distant mountains. They have something to tell us today, just as the fallen heroes who lie in Arlington whisper through the ages. We honor them not only because they are guardians of our liberty, but because they embody the spirit of service; a willingness to find meaning in something greater than themselves. And yet, at this moment - a moment that will define a generation - it is precisely this spirit that must inhabit us all. +  For as much as government can do and must do, it is ultimately the faith and determination of the American people upon which this nation relies. It is the kindness to take in a stranger when the levees break, the selflessness of workers who would rather cut their hours than see a friend lose their job which sees us through our darkest hours. It is the firefighter’s courage to storm a stairway filled with smoke, but also a parent’s willingness to nurture a child, that finally decides our fate. +  Our challenges may be new. The instruments with which we meet them may be new. But those values upon which our success depends - hard work and honesty, courage and fair play, tolerance and curiosity, loyalty and patriotism - these things are old. These things are true. They have been the quiet force of progress throughout our history. What is demanded then is a return to these truths. What is required of us now is a new era of responsibility - a recognition, on the part of every American, that we have duties to ourselves, our nation, and the world, duties that we do not grudgingly accept but rather seize gladly, firm in the knowledge that there is nothing so satisfying to the spirit, so defining of our character, than giving our all to a difficult task. +  This is the price and the promise of citizenship. +  This is the source of our confidence - the knowledge that God calls on us to shape an uncertain destiny. +  This is the meaning of our liberty and our creed - why men and women and children of every race and every faith can join in celebration across this magnificent mall, and why a man whose father less than sixty years ago might not have been served at a local restaurant can now stand before you to take a most sacred oath. +  So let us mark this day with remembrance, of who we are and how far we have traveled. In the year of America’s birth, in the coldest of months, a small band of patriots huddled by dying campfires on the shores of an icy river. The capital was abandoned. The enemy was advancing. The snow was stained with blood. At a moment when the outcome of our revolution was most in doubt, the father of our nation ordered these words be read to the people: +  "Let it be told to the future world...that in the depth of winter, when nothing but hope and virtue could survive...that the city and the country, alarmed at one common danger, came forth to meet [it]." +  America. In the face of our common dangers, in this winter of our hardship, let us remember these timeless words. With hope and virtue, let us brave once more the icy currents, and endure what storms may come. Let it be said by our children’s children that when we were tested we refused to let this journey end, that we did not turn back nor did we falter; and with eyes fixed on the horizon and God’s grace upon us, we carried forth that great gift of freedom and delivered it safely to future generations.sofreedoma.Freedom diff --git a/Pacico/0004/readme.md b/Pacico/0004/readme.md new file mode 100644 index 00000000..4e8b4079 --- /dev/null +++ b/Pacico/0004/readme.md @@ -0,0 +1 @@ +任一个英文的纯文本文件,统计其中的单词出现的个数 diff --git a/Pacico/0005/0005.py b/Pacico/0005/0005.py new file mode 100644 index 00000000..fcd3c2d3 --- /dev/null +++ b/Pacico/0005/0005.py @@ -0,0 +1,20 @@ +# -*- coding: cp936 -*- +def main(): + from PIL import Image + import glob + import os + formats=['.jpg','.bmp','.png','.jpeg','.gif','.wbmp'] + p=R"F:\Trinick\Script\Test\*" + paths=[] + for f in formats: + s=glob.glob(p+f) + if bool(s): + paths.append(s) + for list in paths: + for fp in list: + img=Image.open(fp) + fl,ext=os.path.splitext(fp) + img.thumbnail((1334,750),Image.ANTIALIAS) + img.save(fl+'_thumbnail'+ext) +if __name__=='__main__': + main() diff --git a/Pacico/0005/readme.md b/Pacico/0005/readme.md new file mode 100644 index 00000000..d3669166 --- /dev/null +++ b/Pacico/0005/readme.md @@ -0,0 +1 @@ +你有一个目录,装了很多照片,把它们的尺寸变成都不大于 iPhone5 分辨率的大小。 diff --git a/Pacico/0007/0007.py b/Pacico/0007/0007.py new file mode 100644 index 00000000..7bb04272 --- /dev/null +++ b/Pacico/0007/0007.py @@ -0,0 +1,31 @@ +# -*- coding:cp936 -*- +def main(): + getabspath() + countlines() +import os + +#获取目标目录及其子目录下所有.py文件的绝对路径 +def getabspath(): + all_files=os.walk('F:\Trinick\Script\ShowMeTheCode') + global scripts + scripts=[] + for pardir,chidir,filepaths in all_files: + for fpath in filepaths: + name,ext=os.path.splitext(fpath) + if ext=='.py': + scripts.append(pardir+r"\\"+fpath) + +#计算行数 +def countlines(): + total_lines=0 + empty_lines=0 + for scr in scripts: + for con in open(scr): + if con=='\n': + empty_lines +=1 + total_lines+=1 + print"""Your scripts contain %s line(s) in total, +which include %s empty line(s)""" %(total_lines,empty_lines) +if __name__ =='__main__': + main() + diff --git a/Pacico/0007/readme.md b/Pacico/0007/readme.md new file mode 100644 index 00000000..bc403a87 --- /dev/null +++ b/Pacico/0007/readme.md @@ -0,0 +1 @@ +有个目录,里面是你自己写过的程序,统计一下你写过多少行代码。包括空行和注释,但是要分别列出来。 diff --git a/Pacico/0010/0010.py b/Pacico/0010/0010.py new file mode 100644 index 00000000..b79fe4f7 --- /dev/null +++ b/Pacico/0010/0010.py @@ -0,0 +1,48 @@ + # -*- coding:cp936 -*- +from PIL import Image, ImageDraw , ImageFont, ImageFilter +import random +from random import randint as rdm +import glob +import string +def rmcolor(): + return (random.randrange(50,150),random.randrange(50,150),random.randrange(50,150)) + +def main(): + verify_size=(300,100) + font_lib=glob.glob('c:Windows\Fonts\\*.ttf') + img=Image.new('RGB',verify_size,'white') + draw=ImageDraw.Draw(img) + global verify + verify='' + + #噪点处理 + def pointcolor(): + return(rdm(100,150),rdm(100,150),rdm(100,150)) + for w in xrange(300): + for h in xrange(100): + draw.point((w,h),fill=pointcolor()) + + img=img.filter(ImageFilter.BLUR) + draw=ImageDraw.Draw(img) + + #加入验证字符 + for i in range(1,5): + text=random.choice(string.letters+'123456789') + textcolor=(rmcolor()) + font=ImageFont.truetype(random.choice(font_lib),rdm(70,90)) + x=rdm(40,50) #随机字符位置 + draw.text((x*i,10),fill=textcolor,text=text,font=font) + verify+=text + + #随机划线 + line_times=rdm(0,3) + k=1 + while k<=1: + k+=1 + draw.line(((rdm(0,300),rdm(0,100)),(rdm(0,300),rdm(0,100))),fill=rmcolor(),width=1) + img.show() + #img.save('F:\Trinick\Script\ShowMeTheCode\\010result.jpg') + +if __name__=='__main__': + main() + diff --git a/Pacico/008/008.py b/Pacico/008/008.py new file mode 100644 index 00000000..730b3d08 --- /dev/null +++ b/Pacico/008/008.py @@ -0,0 +1,29 @@ +# -*- coding:utf-8 -*- +from bs4 import BeautifulSoup +import urllib +#修改默认编码 +import sys +a,b,c=sys.stdin,sys.stdout,sys.stderr +reload(sys) +sys.stdin,sys.stdout,sys.stderr=a,b,c +sys.setdefaultencoding('utf8') + + +url='https://github.com/Yixiaohan/show-me-the-code' +def get_html(): + open_url=urllib.urlopen(url) + html=open_url.read() + return html + +def get_text(): + html=get_html() + soup=BeautifulSoup(html) + return soup.text + +def write(): + text=get_text() + newf=open(r'F:\Trinick\Script\ShowMeTheCode\008.txt','w+') + newf.write(text) + newf.close() +#if __name__=='__main__': +write() diff --git a/Pacico/008/008.txt b/Pacico/008/008.txt new file mode 100644 index 00000000..2e6ac925 --- /dev/null +++ b/Pacico/008/008.txt @@ -0,0 +1,565 @@ + +html + + + + + + +Yixiaohan/show-me-the-code · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Skip to content + + + + + + +Sign up +Sign in + + + '"` + +This repository + + + + + + +Explore + + +Features + + +Enterprise + + +Pricing + + + + + + + + + + + + + + + + + Watch + + + 349 + + + + + + Star + + + 1,478 + + + + + + Fork + + + 791 + + + + + +Yixiaohan +/ +show-me-the-code + + + + + + + + + + + + + + + Code + + + + + Issues + + + + + + Pull requests + + + + + + + + + Pulse + + + + + Graphs + + + + + + +HTTPS clone URL + + + + + + + + +Subversion checkout URL + + + + + + + +You can clone with + '"` HTTPS or '"` Subversion. + + + + + + + Download ZIP + + + + + + + + Python 练习册,每天一个小程序 + + + + + + + + + + + 27 + + commits + + + + + + + 1 + + branch + + + + + + + 0 + + releases + + + + + + + + Fetching contributors + + + + + + + + + + + + + + + + +Branch: +master + + + + + +Switch branches/tags + + + + + + + + +Branches + + +Tags + + + + + + + + + + master + + + +Nothing to show + + + + +Nothing to show + + + + +show-me-the-code/ + + + + + + + + Latest commit + + 53f7ab4 + +Aug 10, 2015 + + + +Yixiaohan + +Pull Request 请提交你个人的仓库 URL 链接地址。现在项目太大了,提交 URL 吧 + +… + + +Pull Request 请提交你个人的仓库 URL 链接地址。现在项目太大了,提交 URL 吧 + + +Permalink + + + + +Failed to load latest commit information. + + + + + + + +README.md + + + +Pull Request 请提交你个人的仓库 URL 链接地址。现在项目太大了,提交 URL 吧 + + + +Aug 10, 2015 + + + + + + + + + README.md + +Python 练习册,每天一个小程序 +说明: + +Python 练习册,每天一个小程序。注:将 Python 换成其他语言,大多数题目也适用 +不会出现诸如「打印九九乘法表」、「打印水仙花」之类的题目 +点此链接,会看到每个题目的代码, 欢迎大家 Pull Request 出题目,贴代码(Gist、Blog皆可),Pull Request 请提交你个人的仓库 URL 链接地址。现在项目太大了,提交 URL 吧 :-) +本文本文由@史江歌(shijiangge@gmail.com QQ:499065469)根据互联网资料收集整理而成,感谢互联网,感谢各位的分享。鸣谢!本文会不断更新。 + + +Talk is cheap. Show me the code.--Linus Torvalds + + +第 0000 题:将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。 +类似于图中效果 + +第 0001 题:做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)? +第 0002 题:将 0001 题生成的 200 个激活码(或者优惠券)保存到 MySQL 关系型数据库中。 +第 0003 题:将 0001 题生成的 200 个激活码(或者优惠券)保存到 Redis 非关系型数据库中。 +第 0004 题:任一个英文的纯文本文件,统计其中的单词出现的个数。 +第 0005 题:你有一个目录,装了很多照片,把它们的尺寸变成都不大于 iPhone5 分辨率的大小。 +第 0006 题:你有一个目录,放了你一个月的日记,都是 txt,为了避免分词的问题,假设内容都是英文,请统计出你认为每篇日记最重要的词。 +第 0007 题:有个目录,里面是你自己写过的程序,统计一下你写过多少行代码。包括空行和注释,但是要分别列出来。 +第 0008 题:一个HTML文件,找出里面的正文。 +第 0009 题:一个HTML文件,找出里面的链接。 +第 0010 题:使用 Python 生成类似于下图中的字母验证码图片 + + +阅读资料 + +第 0011 题: 敏感词文本文件 filtered_words.txt,里面的内容为以下内容,当用户输入敏感词语时,则打印出 Freedom,否则打印出 Human Rights。 +北京 +程序员 +公务员 +领导 +牛比 +牛逼 +你娘 +你妈 +love +sex +jiangge + +第 0012 题: 敏感词文本文件 filtered_words.txt,里面的内容 和 0011题一样,当用户输入敏感词语,则用 星号 * 替换,例如当用户输入「北京是个好城市」,则变成「**是个好城市」。 +第 0013 题: 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-) + +参考代码 + +第 0014 题: 纯文本文件 student.txt为学生信息, 里面的内容(包括花括号)如下所示: +{ + "1":["张三",150,120,100], + "2":["李四",90,99,95], + "3":["王五",60,66,68] +} + +请将上述内容写到 student.xls 文件中,如下图所示: + + +阅读资料 腾讯游戏开发 XML 和 Excel 内容相互转换 + +第 0015 题: 纯文本文件 city.txt为城市信息, 里面的内容(包括花括号)如下所示: +{ + "1" : "上海", + "2" : "北京", + "3" : "成都" +} + +请将上述内容写到 city.xls 文件中,如下图所示: + +第 0016 题: 纯文本文件 numbers.txt, 里面的内容(包括方括号)如下所示: +[ + [1, 82, 65535], + [20, 90, 13], + [26, 809, 1024] +] + +请将上述内容写到 numbers.xls 文件中,如下图所示: + +第 0017 题: 将 第 0014 题中的 student.xls 文件中的内容写到 student.xml 文件中,如 +下所示: + + + + +{ + "1" : ["张三", 150, 120, 100], + "2" : ["李四", 90, 99, 95], + "3" : ["王五", 60, 66, 68] +} + + + +第 0018 题: 将 第 0015 题中的 city.xls 文件中的内容写到 city.xml 文件中,如下所示: + + + + +{ + "1" : "上海", + "2" : "北京", + "3" : "成都" +} + + + +第 0019 题: 将 第 0016 题中的 numbers.xls 文件中的内容写到 numbers.xml 文件中,如下 +所示: + + + + + +[ + [1, 82, 65535], + [20, 90, 13], + [26, 809, 1024] +] + + + + +第 0020 题: 登陆中国联通网上营业厅 后选择「自助服务」 --> 「详单查询」,然后选择你要查询的时间段,点击「查询」按钮,查询结果页面的最下方,点击「导出」,就会生成类似于 2014年10月01日~2014年10月31日通话详单.xls 文件。写代码,对每月通话时间做个统计。 +第 0021 题: 通常,登陆某个网站或者 APP,需要使用用户名和密码。密码是如何加密后存储起来的呢?请使用 Python 对密码加密。 + +阅读资料 用户密码的存储与 Python 示例 +阅读资料 Hashing Strings with Python +阅读资料 Python's safest method to store and retrieve passwords from a database + +第 0022 题: iPhone 6、iPhone 6 Plus 早已上市开卖。请查看你写得 第 0005 题的代码是否可以复用。 +第 0023 题: 使用 Python 的 Web 框架,做一个 Web 版本 留言簿 应用。 +阅读资料:Python 有哪些 Web 框架 + + + +第 0024 题: 使用 Python 的 Web 框架,做一个 Web 版本 TodoList 应用。 + + + +第 0025 题: 使用 Python 实现:对着电脑吼一声,自动打开浏览器中的默认网站。 +例如,对着笔记本电脑吼一声“百度”,浏览器自动打开百度首页。 + +关键字:Speech to Text + +参考思路: +1:获取电脑录音-->WAV文件 + python record wav +2:录音文件-->文本 +STT: Speech to Text + +STT API Google API + +3:文本-->电脑命令 + + + + + + + + + + + +Status +API +Training +Shop +Blog +About +Pricing + + + + + +© 2015 GitHub, Inc. +Terms +Privacy +Security +Contact +Help + + + + + + + + + Something went wrong with that request. Please try again. + + + + + +You signed in with another tab or window. Reload to refresh your session. +You signed out in another tab or window. Reload to refresh your session. + + + diff --git a/Pacico/008/readme.md b/Pacico/008/readme.md new file mode 100644 index 00000000..a073434a --- /dev/null +++ b/Pacico/008/readme.md @@ -0,0 +1 @@ +一个HTML文件,找出里面的正文。 diff --git a/Pacico/011and012/011012.py b/Pacico/011and012/011012.py new file mode 100644 index 00000000..4701129a --- /dev/null +++ b/Pacico/011and012/011012.py @@ -0,0 +1,33 @@ +# -*- coding:cp936 -*- + +import re +lib=open(r'F:\Trinick\Script\ShowMeTheCode\011FilteredWords.txt') +fil=[] +user=raw_input('Enter plz:') +def get_filters(): + for word in lib: + word=re.sub('\n','',word) + fil.append(word) + +def replace(): + global tf,user + tf= '' + for word in fil: + if word in user: + replace='*'* len(word) + user=re.sub(word, replace , user) + tf= True + +def main(): + get_filters() + replace() + print user + while tf: + print 'Freedom' + return + break + print 'Human Rights' + +if __name__=='__main__': + main() + diff --git a/Pacico/013/013.py b/Pacico/013/013.py new file mode 100644 index 00000000..cc363436 --- /dev/null +++ b/Pacico/013/013.py @@ -0,0 +1,26 @@ +# -*- coding: cp936 -*- +import re +import urllib +url='http://tieba.baidu.com/p/2166231880' +def get_html(url): + url=urllib.urlopen(url) + html=url.read() + return html + +def get_img_list(): + r=r'src="(.+?\.jpg)".+?bdwater' + html=get_html(url) + reg=re.compile(r) + img_list=re.findall(reg, html) + return img_list + +def download(): + img_list=get_img_list() + x=1 + for img in img_list: + urllib.urlretrieve(img, r'F:\Trinick\Script\ShowMeTheCode\013\%s.jpg'%x) + x+=1 +if __name__=='__main__': + + download() + diff --git a/Pacico/013/readme.md b/Pacico/013/readme.md new file mode 100644 index 00000000..fe57d005 --- /dev/null +++ b/Pacico/013/readme.md @@ -0,0 +1,2 @@ +用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 +http://tieba.baidu.com/p/2166231880 diff --git a/Pacico/014/014.py b/Pacico/014/014.py new file mode 100644 index 00000000..5e3fd58a --- /dev/null +++ b/Pacico/014/014.py @@ -0,0 +1,29 @@ +# -*- coding:cp936 -*- +import xlwt +xlr_file=r'F:\Trinick\Script\ShowMeTheCode\014.xls' +txt_file=r'F:\Trinick\Script\ShowMeTheCode\014.txt' + + +def get_con(): + txt=open(txt_file) + con=txt.read() + con=eval(con) + return con + +def write_xls(): + con=get_con() + book=xlwt.Workbook(encoding='cp936') + s=book.add_sheet('info',cell_overwrite_ok=True) + r=0 + for k in con: + s.write(r,0,k) + ncol=1 + for c in con[k]: + s.write(r,ncol,c) + ncol+=1 + r+=1 + book.save(xlr_file) + +if __name__=='__main__': + write_xls() + print 'Finish' diff --git a/Pacico/014/readme.md b/Pacico/014/readme.md new file mode 100644 index 00000000..47c29a75 --- /dev/null +++ b/Pacico/014/readme.md @@ -0,0 +1,7 @@ +纯文本文件 student.txt为学生信息, 里面的内容(包括花括号)如下所示: + +{ + "1":["张三",150,120,100], + "2":["李四",90,99,95], + "3":["王五",60,66,68] +}