Yadda ake ganin yanayi a cikin Terminal tare da Budadden Yanayi

yanayin-bude-yanayi

A cikin wannan labarin muna so mu nuna muku yadda zamu iya ganin yanayin yanzu a cikin Terminal a cikin hanya mai matukar sanyi. Don wannan za mu yi amfani da shi Bude Yanayi da API ɗinsa don nuna yanayin ta Terminal ɗinmu.

Hanya ce mai ɗan tsayi, ko kuma aƙalla ba mai sauƙi ba kamar yadda ake iya gani, tunda dole ne mu yi hakan clone ma'ajiyarka ta GitHub sannan ka kara guda Maballin API kuma a karshe gudanar da shirin. Bugu da kari, don mafi yawan sha'awar, wannan aikace-aikacen yana aiki tare Masu aikin jinya, wani «mai hoto» laburare na tashar, wanda a bayyane yake mu ma za mu girka, da shi za mu iya aiwatar da zane-zane bisa haruffan rubutu. Wannan shine dalilin da ya sa a Ubunlog muke koyar da shi mataki-mataki don ku iya yin shi ta hanya mafi sauƙi. Mun fara.

Yi rijista ka sami Mabuɗin API

Mataki na farko shine yin rijista akan ka Yanar gizo don daga baya iya samun Mabuɗin API (APi Key). Don yin wannan kawai dole ne mu shigar da sunan mai amfani, imel ɗin mu, da kalmar sirri da zamu rubuta sau biyu, kamar koyaushe, kamar yadda ya bayyana a hoto mai zuwa.

Hoton hotuna daga 2016-05-10 15:18:42

Tsarin zai ci gaba zuwa ba mu da maɓallin API, kamar yadda muke gani a hoto na gaba. Kamar yadda kuke gani, zamu iya nuna sunan kamfanin mu (ko wurin da zamuyi amfani da wannan widget din) sannan, ta yaya zaku kuma gani, an riga an samar mana da Key ɗin API. Da kyau, rubuta Kalmar wucewa a cikin amintaccen wuri, ko kuma kawai kar a rufe mai binciken, saboda za mu buƙace shi daga baya.

api-mabudin-budewa

 

Girka app

Yanzu muna da Mabuɗin API, zamu iya ci gaba zuwa shigar da app. Kamar yadda muka fada a farkon labarin, don girka shi, dole ne mu sanya ma'ajiyar GitHub ɗinmu a cikin kundin adireshin da muke so.

Domin amfani da wannan aikace-aikacen, kuna buƙatar samun jerin shirye-shiryen da aka sanya a baya: Masu aikin jinya (dakin karatu mai hoto na Terminal), Git (don sarrafa wurin ajiya), bc (GNU kalkuleta), Curl (don samun fayiloli daga yanar gizo) kuma a ƙarshe grep (don tace kayan aikin umarni). Don yin wannan muna aiwatar da umarni mai zuwa:

sudo apt-samun inganci
sudo apt-samun shigar ncurses-bin git bc curl grep

Da zarar an shigar da dukkan shirye-shiryen da suka dace, yanzu zamu iya shigar da aikace-aikacen. Don wannan muke zamu je jakarmu y muna adana wurin ajiyewa GitHub na aikace-aikacen don samo shi a kan PC ɗin mu. Wato, muna aiwatar da waɗannan umarni guda biyu masu zuwa:

cd ~

git clone https://github.com/szantaii/bash-weather.git

Idan ka duba sosai, za ka ga cewa kundin adireshi ake kira / bash-yanayi / Ya ƙunshi dukkan rubutun aikace-aikacen Bash. To yanzu mataki na gaba na iya zama motsa abun ciki daga wannan kundin adireshin zuwa wani ɓoyayyen shugabanci da ake kira, misali, .bash-weather (kamar yadda kuka riga kuka sani ./ yana nuna cewa ɓoyayyen shugabanci ne). Don aiwatar da wannan matakin, kawai gudu:

mv bash-yanayi / .bash-weather /

A ƙarshe zamu je ga kundin adireshi:

cd ~ / .bash-yanayi /

A yanzu haka shine lokacin da muke bukata gaya ma aikace-aikacen menene API Key din mu. Don yin wannan, za mu buɗe fayil ɗin bude shafin yanar gizo.key kuma a ciki muna kwafin kalmar sirrinmu. Ta hanya mai zuwa:

key-api-key

Mataki na ƙarshe shine a ba da babban rubutun izinin izini, ta hanyar chmod:

chmod + x bash -weather.sh

A ƙarshe, yanzu zamu iya gudanar da shirin kawai tare da:

bash bash-kamar.sh

Ya da kyau:

./bash-damana.sh

Ya kamata yayi kama da wani abu kamar haka:

Hoton hotuna daga 2016-05-10 15:50:12

Bugu da kari, shirin da muka aiwatar yana da jerin sigogin daidaitawa, wadanda sune masu zuwa:

  • -k  Ba ka damar saka da API Key daga layin umarni, idan da ba mu saka shi a cikin fayil ɗin ba bude shafin yanar gizo.key
  • -h  Nos yana nuna allon taimako.
  • -t "sunan gari"  Da kanka saita birni da kanka don bincike.
  • -c lambar kasar  Saita saita kasar da hannu bisa lambar harafi biyu (Argentina itace AR).
  • -c lambar kasar  Saita saita kasar da hannu bisa lambar harafi biyu (Argentina itace AR).

Don haka, idan kun gudu misali:

./bash-weather.sh -t "Brazil" -f

Zai nuna mana yanayin Brazil (ta hanyar siga -t «Brazil») kuma hakan zai nuna mana yanayin yanayi tare da launuka (ta hanyar siga -f).

Gudanar da shirin daga kowane kundin adireshi

Gaskiyar ita ce, da alama abin ɗan damuwa ne don zuwa kundin adireshi kowane lokaci .bash-yanayi a cikin jakar sirri sannan kuma gudanar da rubutun. To abin tambaya shine: Shin yana yiwuwa a gudanar da shirin daga kowane kundin adireshi kuma ta hanya mai sauƙi?

Amsar a bayyane take. Kamar yadda kuka sani, Linux yana da kundin adireshi mai suna / bin / Ya ƙunshi manya-manyan shirye-shirye ko rubutun da za mu iya aiwatar da su kai tsaye daga tashar. Da kyau, ra'ayin shine rubuta ɗan rubutu a cikin bash cewa mu Gudun Yanayi, sannan kuma adana wannan rubutun ciki / bin /.

Kamar yadda muka sani, rubutun da muke gudanarwa don fara aikace-aikacen, ana kira baw-tar-gari.sh, yana cikin ~ / .bash-yanayi / (ɓoyayyen adireshi a cikin babban fayil ɗinmu, wanda zamu iya gani ta danna Ctrl + H). Sannan kawai zamu ƙirƙiri rubutun wato je wannan kundin adireshi, kuma daga baya gudu ba-sara-gari.sh. Bugu da kari, kamar yadda muka fada, tabbatacce ne cewa wannan rubutun yana cikin kundin adireshin / binIdan ba haka ba, ba za mu iya aiwatar da shi daga kowane kundin adireshi a cikin tashar ba.

Don wannan dole ne mu ƙirƙiri fayil mara komai kira, misali, yanayi_. Zan ƙirƙira shi a kan tebur. Muna aiwatarwa:

cd ~ / Desktop

taba yanayi na

Nan gaba zamu bude fayil din yanayi_ y mun kwafa abubuwan da ke gaba:

#! / bin / sh

cd ~ / .bash-yanayi /

./bash-damana.sh

Hakanan zamu iya kwafa abun ciki ta hanyar m:

amsa kuwwa -e '#! / bin / sh \ n \ n cd ~ / .bash-weather / \ n \ n ./bash-weather.sh\n' | sudo tee ~ / Desktop / my_climate

Sannan muna motsa fayil din yanayi_ zuwa babban fayil / bin. Saboda wannan muna buƙatar samun izini na superuser, don haka zamu iya aiwatar da waɗannan masu zuwa:

sudo mv ~ / tebur / my_climate / bin

Zai tambaye mu kalmar sirrinmu kuma a ƙarshe za a kwafe fayil ɗin a cikin / bin.

Daga yanzu, duk lokacin da muke rubutu yanayi_ a cikin tasharDaga kowane kundin adireshi, Bude Yanayi za'a kashe kuma zamu ga yanayin da ake magana akai. Da sauki?

Muna fatan wannan karamin karatun ya taimaka muku. Idan kuna da wasu tambayoyi ko matsaloli, bar shi a cikin ɓangaren maganganun kuma a cikin Ubunlog za mu yi farin cikin taimaka muku 🙂


Abubuwan da ke cikin labarin suna bin ka'idodinmu na ka'idojin edita. Don yin rahoton kuskure danna a nan.

Sharhi, bar naka

Bar tsokaci

Your email address ba za a buga.

*

*

  1. Mai alhakin bayanan: Miguel Ángel Gatón
  2. Dalilin bayanan: Gudanar da SPAM, gudanar da sharhi.
  3. Halacci: Yarda da yarda
  4. Sadarwar bayanan: Ba za a sanar da wasu bayanan ga wasu kamfanoni ba sai ta hanyar wajibcin doka.
  5. Ajiye bayanai: Bayanin yanar gizo wanda Occentus Networks (EU) suka dauki nauyi
  6. Hakkoki: A kowane lokaci zaka iyakance, dawo da share bayanan ka.

  1.   Antonio m

    Barka dai, na gode sosai saboda wannan babban matsayi, ga sabon shiga kamar ni abin birgewa ne. Af, waɗanne aikace-aikace kuke da su don nuna duk bayanan da kuka gani a hannun dama, a cikin hoton allo? Sanya masu sarrafawa, ƙwaƙwalwa, baturi, hanyoyin sadarwa, da dai sauransu. Sake godewa sosai!