Форум сайта python.su
class ComboBoxWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="ComboBox Example") self.set_border_width(10) vbox = Gtk.Box(spacing=6) ifaces_combo = Gtk.ComboBoxText() ifaces_combo.set_entry_text_column(0) ifaces_combo.connect("changed", self.on_ifaces_combo_changed, self.on_ifaces_combo_changed) for iface in ifaces: ifaces_combo.append_text(iface) switch = Gtk.Switch() switch.connect("notify::active", self.on_switch_activated) switch.set_active(False) vbox.pack_start(ifaces_combo, False, False, 0) vbox.pack_start(switch, True, True, 0) self.add(vbox) def on_ifaces_combo_changed(self, combo): sel_iface = combo.get_active_text() if sel_iface != None: print("Selected interface =%s" % sel_iface) def on_switch_activated(self, switch, gparam): if switch.get_active(): state = "on" else: state = "off" print("Switch was turned", state) win = ComboBoxWindow() win.connect("delete-event", Gtk.main_quit) win.show_all() Gtk.main()
def prepareSQL(): con=odiRef.getJDBCConnection("SRC") #соединение с БД sql='''<%=odiRef.getOption("zapis")%> ''' #Выполнение запроса - возвращает названия return con.prepareStatement(sql) #нужных таблиц из системной prep = prepareSQL() rs=prep.executeQuery() f=open("C:\Temp\droptab4.txt","a") # Открываем файл на компе для записи while(rs.next()): #Пока есть записи записываем названия таблиц в файл. data=rs.getString("OBJ_NAME") #В этот же файл должна быть запись размера таблиц в мб f.write(data +" \n") f.close() # Закрываем файл prep.close()
while(rs.next()): data=rs.getString("OBJ_NAME") s=os.path.getsize(data) f.write(data +" \n" + s) f.close() prep.close()
class GroupForm(ModelForm): class Meta: model = GroupsList fields = ['link'] def clean(self): link = self.cleaned_data.get('link') vk_api = get_api() info = get_grop_info(link, vk_api) if info['count']: if info['count'] < 0: raise ValidationError('В группе нет участников') elif info['count'] > 10000: raise ValidationError('Слишком нмого участников >10000') else: raise ValidationError('Проблема с получением данных') return self.cleaned_data
def group_add(request, username): if request.POST: user = User.objects.get(username=username) form = GroupForm(request.POST) if form.is_valid(): input_group = form.save(commit=False) group_link = input_group.link group_info = get_grop_info(input_group.link, get_api()) try: group = GroupsList.objects.get(link=group_link) try: group.author.add(user.id) except Exception as e: print(e) insert_group_info(input_group.link, group_info) except: input_group = form.save() group_link = input_group.link group = GroupsList.objects.get(link=group_link) group.author.add(user.id) insert_group_info(input_group.link, group_info) else: return redirect('/', {'group_form': form}) return redirect('/', {'group_form': form})
<form action="manage_group/group_add/{{ username }}/" method="post"> {{ group_form.as_p }} <input type="submit" value="Добавить группу"> {% csrf_token %} </form>
self.avatar.setStyleSheet("""background-repeat: none; background-image: url(.data/img/avatarDemo.png); background-position:center center; border-radius:50px; border: 1px solid transparent;""")
self.avatar.setStyleSheet("""background-repeat: none; background-image: url(http://pp.userapi.com/c637829/v637829243/4f011/kFp1nXPCef4.jpg); background-position:center center; border-radius:50px; border: 1px solid transparent;""")
import pyb
pin1=pyb Pin('X22', pyb.Pin.IN, pull=pyb.Pin.PULL_DOWN)
pin2=pybPin ('X21', pyb.Pin.OUT, pull=pyb.Pin.PULL_DOWN)
if pin1.high()
pin2.high()
## -*- coding: utf-8 -*- # одключение библиотек from tkinter import * import requests from bs4 import BeautifulSoup import csv #Графическая оболочка root = Tk() root.title('Парсер для Avito') root.geometry ('1500x830') width = root.winfo_screenwidth() height = root.winfo_screenheight() lab1 = Label(root,font='10', text = "Ввидеты ссылку на товары:") tx1 =Entry(root,width= 45,font='10') cb1 = Checkbutton(root, text= "Заголовок товара",font='8',onvalue = '1', offvalue = '0') cb2 = Checkbutton(root, text= "Цена товара",font='8',onvalue = '1', offvalue = '0') cb3 = Checkbutton(root, text= "Метро",font='8',onvalue = '1', offvalue = '0') cb4 = Checkbutton(root, text= "Ссылка на продукт",font='8',onvalue = '1', offvalue = '0') cb5 = Checkbutton(root, text= "Дата размещения на сайте",font='8',onvalue = '1', offvalue = '0') cb6 = Checkbutton(root, text= "Описание товара ",font='8',onvalue = '1', offvalue = '0') cb9 = Checkbutton(root, text= "Имя продавца",font='8',onvalue = '1', offvalue = '0') lab2 = Label(root, width= 30,height = 3,font='10', text = "Выберите метод сохранения файла:") cb10 = Checkbutton(root, text= "Сохранить",font='8') cb12 = Checkbutton(root, text= "Не сохранять",font='8') tx2 = Text(root,width = 100 , height = 50) scr = Scrollbar(root,command=tx2.yview) tx2.configure(yscrollcommand=scr.set,) scr2 = Scrollbar(root,command=tx2.yview,orient= 'horizontal') tx2.configure(xscrollcommand=scr2.set) but = Button(root ,text = 'SAVE', font = 100) but2= Button(root, text='Парсеть' , font = 200) #вывод на экран lab1.place(x = 1, y = 1) tx1.place ( x = 220 ,y = 1) cb1.place ( x = 1 , y = 30) cb2.place( x = 1,y =60) cb3.place( x = 1,y =90) cb4.place( x = 1,y =120) cb5.place( x = 200,y =30) cb6.place( x = 200,y =60) cb9.place(x = 1, y = 150) lab2.place( x = 1, y = 220) cb10.place(x = 1, y = 265) cb12.place(x = 180 , y = 265) tx2.place (x = 680, y = 1) scr.place (x = 662,y = 1) scr2.place( x = 680, y = 807) but2.place (x= 1 ,y = 180) but.place ( x = 1, y = 300) #основной парсер def get_html(url):# получение url кода r = requests.get(url) return r.text def get_total_pages(html):#считывание кол-ва страниц soup = BeautifulSoup(html, 'lxml') pages = soup.find('div',class_='pagination-pages').find_all('a',class_='pagination-page')[-1].get('href') total_pages = pages.split('=')[1].split('&')[0] return int(total_pages) ads = soup.find('div',class_='catalog-list').find_all('div',class_='item_table') for ad in ads: if cb1 == '1': title = ad.find('div',class_='description').find('h3').text.strip()#Заголовок else: pass if cb4 == '1': url = 'https://www.avito.ru' + ad.find('div',class_='discription').find('h3').find('a').get('href')#Ссылка else: pass if cb2 == '1': price = ad.find('div',class_='about').text.strip()#цена else: pass if cb3 =='1': metro = ad.find('div',class_='data').find_all('p')[-1].text.strip()#метро else: pass if cb5 == '1': data_tovara = ad.find('div', class_='data').find('div',class_='clearfix').find('div',class_='data c-2').text.strip()#дата размещения товара else: pass if cb6 == '1': opisanie = ad.find('div',class_='item-view-block').find('p').text.strip()#описание товара else: pass if cb9 =='1': saller = ad.find('div',class_='seller-info-name').find('a').text.strip()#продавец else: pass global data data = {'title':title, 'price':price, 'metro':metro, 'url':url, 'data_tovara':data_tovara, 'opisanie':opisanie, 'saller':saller} def write_csv(data): with open('avito.csv','w') as f: writer = csv.writer(f) writer.writerow(( data['title'],data['price'],data['metro'],data['data_tovara'],data['opisanie'],data['saller'],data['url'] )) def print_(event): soup = BeautifulSoup(html,'lxml') write_csv(data) def get_page_data(html): soup = BeautifulSoup(html,'lxml') but.bind('<Button-1>',pars) but2.bind('<Button-1>',print_) def main(): #https://www.avito.ru/novosibirsk?p=1&q=iphone+5s url = 'https://www.avito.ru/novosibirsk?p=1&q=iphone+5s' base_url = 'https://www.avito.ru/novosibirsk?' lab = Label(root, text="", font="Arial 12",height=3) page_part = 'p=' query_part = '&q=iphone+5s' total_pages = get_total_pages(get_html(url)) for i in range(1, total_pages): url_gen = base_url + page_part + str(i) + query_part html = get_html(url_gen) if __name__ == '__main__': main() root.mainloop()
# -*- coding: utf-8 -*- import random from time import sleep from threading import Thread from sys import stdout from grab import Grab timeout = 10 connect_timeout = 10 def c(con, url, post = 0, headers = 0, proxy = 0): global timeout, connect_timeout while True: con.setup(timeout = timeout, connect_timeout = connect_timeout) if post: con.setup(post = post) if headers: con.setup(headers = headers) if proxy: con.setup(proxy_type = "http", proxy = proxy) try: con.go(url) break except Exception as e: if str(e).find("timeout") != -1: stdout.write("#T " + url + " "*5 + "\r") else: stdout.write(str(e)[:50] + "\r") sleep(1 if url.find("likeorgasm") != -1 else 3) def lo(u, con): while True: c(con, "https://api.likeorgasm.ru/method/user.get?" + u) try: con.doc.json break except: print(con.doc.unicode_body()) def _thread(): g = Grab() while True: try: lo("user_token=228", g) stdout.write(g.doc.unicode_body() + " " + str(random.randint(1000,9999)) + "\r") except Exception as e: print(e) for _ in range(100): Thread(target = _thread).start() sleep(.15)