Skip to content

Commit c34ae5c

Browse files
author
mustafa
committed
today
1 parent baff9b9 commit c34ae5c

File tree

6 files changed

+167
-3
lines changed

6 files changed

+167
-3
lines changed

altislem.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import subprocess
2+
import time
3+
4+
"""
5+
cikti = subprocess.run(["df","-h"],stdout=subprocess.PIPE)
6+
7+
print(cikti.stdout.decode("utf-8"))
8+
"""
9+
gecmis_islem = ""
10+
while True:
11+
p1 = subprocess.Popen(["dmesg"], stdout=subprocess.PIPE)
12+
p2 = subprocess.Popen(["grep", "usb"], stdin=p1.stdout, stdout=subprocess.PIPE)
13+
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
14+
output = p2.communicate()[0]
15+
son_satir = output.decode("utf-8").split("\n")[-2]
16+
son_islem = son_satir.split("[")[1].split("]")[0]
17+
if gecmis_islem != son_islem:
18+
gecmis_islem = son_islem
19+
print(son_satir)
20+
time.sleep(2)

logging_example.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import logging
2+
FORMAT = '[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s'
3+
logging.basicConfig(filename="hata.log",format=FORMAT,level=logging.WARNING)
4+
logging.warning('Watch out!') # will print a message to the console
5+
logging.info('I told you so') # will not print anything
6+
logging.critical("Dalek! Dalek!")
7+
logging.error("Dalek! Dalek!")

logging_uygulama.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import json
2+
import requests
3+
import logging
4+
FORMAT = '[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s'
5+
logging.basicConfig(filename="hata2.log",format=FORMAT,level=logging.DEBUG)
6+
class Movie():
7+
title = None
8+
id = None
9+
10+
def __init__(self, title, id):
11+
logging.info('Movie Sınıfı {title}, {id} parametreleri ile Oluşturuldu'.format(title=title,id=id))
12+
13+
self.session = requests.session()
14+
self.title = title
15+
self.id = id
16+
17+
def get_info(self):
18+
logging.info('{title}, {id} infosu istendi'.format(title=self.title, id=self.id))
19+
20+
try:
21+
data = self.session.get('https://www.imdb.com/title/{id}/?ref_=nv_sr_1'.format(id=self.id)).content.decode(
22+
'utf-8')
23+
return data.split('<span itemprop="ratingValue">')[1].split('<')[0]
24+
except:
25+
return "N/A"
26+
27+
def __str__(self):
28+
return "{} ({})".format(self.title, self.id)
29+
30+
def __unicode__(self):
31+
return "{} ({})".format(self.title, self.id)
32+
33+
34+
class Parser():
35+
session = None
36+
search_results = []
37+
38+
def __init__(self):
39+
self.session = requests.session()
40+
logging.info('Parser Sınıfı Oluşturuldu')
41+
42+
def search(self, keyword):
43+
logging.info('{key} sözcüğü ile arama yapıldı'.format(key=keyword))
44+
45+
data = self.session.get(
46+
'https://v2.sg.media-imdb.com/suggests/{aramailk}/{arama}.json'.format(
47+
aramailk=keyword[0],
48+
arama=keyword))
49+
content = data.content.decode("utf-8")
50+
51+
suggests_json = content.split('imdb${sup}('.format(sup=keyword))[1][:-1]
52+
suggests = json.loads(suggests_json)
53+
logging.info('Data başarılı bir şekilde çekildi')
54+
55+
for suggest in suggests.get('d'):
56+
self.search_results.append(Movie(**{
57+
"title": suggest.get('l'),
58+
"id": suggest.get('id')
59+
}))
60+
logging.info('Kendimi return ettim')
61+
62+
return self
63+
64+
def get_results(self):
65+
logging.info('Result istendi')
66+
67+
return self.search_results
68+
69+
70+
parse = Parser()
71+
for movie in parse.search("supernat").get_results():
72+
print(movie, movie.get_info())
73+
74+
try:
75+
d = 0/0
76+
except ZeroDivisionError as e:
77+
logging.exception("Sıfıra bölünme",exc_info=e)

process_vs_thread.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
import requests
3+
import time
4+
from multiprocessing.pool import ThreadPool
5+
6+
user_agent = {'User-agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0'}
7+
8+
9+
def download_site(page):
10+
response = requests.get("https://eksisozluk.com/python--109286?p={}".format(page), headers=user_agent)
11+
return response.text
12+
13+
thread_havuzu = ThreadPool(69)
14+
data = []
15+
baslangic = time.time()
16+
data = thread_havuzu.map(download_site, range(1, 70))
17+
bitis = time.time()
18+
print(bitis-baslangic)

random_grup.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import curses
2+
import os
3+
import time
4+
from random import randint
5+
6+
kisiler = ["Betül Tezel",
7+
"Orçun",
8+
"Deryak",
9+
"Elis",
10+
"Semiha",
11+
"Muzaffer",
12+
"Tolga",
13+
"Adil",
14+
"Erkan",
15+
"İlter",
16+
"Vahit",
17+
"Furkan",
18+
"Kadir",
19+
"Betül",
20+
"Elif",
21+
"Mehmet",
22+
"Seda",
23+
"Eda",
24+
"Defne",
25+
"Esra",
26+
"Osman",
27+
"Hayri",
28+
"Burak",
29+
"Ertan"]
30+
31+
32+
for z in range(0,4):
33+
grup = []
34+
35+
print("GRUP",z,"#"*100)
36+
for i in range(0,6):
37+
cikan = kisiler[randint(0,len(kisiler)-1)]
38+
grup.append(cikan)
39+
kisiler.remove(cikan)
40+
41+
if i < 9:
42+
time.sleep(0.2)
43+
else:
44+
time.sleep(0.1)
45+
print(grup)

random_secici.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
"Adil",
1414
"Erkan",
1515
"İlter",
16-
"İlter",
17-
"İlter",
1816
"Vahit",
1917
"Furkan",
2018
"Kadir",
@@ -29,7 +27,6 @@
2927
"Hayri",
3028
"Burak",
3129
"Ertan",
32-
"İlteriş"
3330
]
3431
stdscr = curses.initscr()
3532

0 commit comments

Comments
 (0)