Форум сайта python.su
#! coding: utf-8 __author__ = 'iam' from scrapy.contrib.spiders import CrawlSpider, Rule from scrapy.contrib.linkextractors import LinkExtractor from scrapy.item import Item, Field from scrapy.contrib.loader import XPathItemLoader from scrapy.contrib.loader.processor import TakeFirst from scrapy.http import Request, FormRequest from scrapy import Selector # class ScrapyTestItem(Item): title = Field() url = Field() class Test03Loader(XPathItemLoader): default_output_processor = TakeFirst() class ScrapyTestSpider(CrawlSpider): name = "cr01" allowed_domains = ["ecom.elko.ru"] start_urls = ["https://ecom.elko.ru/Account/Login", "https://ecom.elko.ru/Catalog/Category/SCO" ] rules = ( Rule(LinkExtractor( allow=('https://ecom.elko.ru/Catalog/Product/')), callback='parse_item', follow=False), ) def parse(self, response): return [FormRequest.from_response(response, formdata={'username': 'tiscom6', 'password': '6307860'}, callback=self.after_login)] def after_login(self, response): # check login succeed before going on if "authentication failed" in response.body: self.log("Login failed", level=log.ERROR) return def parse_item(self, response): hxs = HtmlXPathSelector(response) l = Test03Loader(ScrapyTestItem(), hxs) l.add_xpath('title', "//h1/text()") l.add_value('url', response.url) return l.load_item()
2016-12-17 23:46:21 [scrapy] INFO: Spider opened 2016-12-17 23:46:21 [scrapy] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 i tems (at 0 items/min) 2016-12-17 23:46:21 [scrapy] DEBUG: Telnet console listening on 127.0.0.1:6023 2016-12-17 23:46:21 [scrapy] DEBUG: Redirecting (302) to <GET https://ecom.elko. ru/Account/Login?ReturnUrl=%2fCatalog%2fCategory%2fSCO> from <GET https://ecom.e lko.ru/Catalog/Category/SCO> 2016-12-17 23:46:21 [scrapy] DEBUG: Crawled (200) <GET https://ecom.elko.ru/Acco unt/Login> (referer: None) 2016-12-17 23:46:21 [scrapy] DEBUG: Crawled (200) <GET https://ecom.elko.ru/Acco unt/Login?ReturnUrl=%2fCatalog%2fCategory%2fSCO> (referer: None) 2016-12-17 23:46:21 [scrapy] DEBUG: Crawled (200) <POST https://ecom.elko.ru/Acc ount/Login> (referer: https://ecom.elko.ru/Account/Login) 2016-12-17 23:46:22 [scrapy] DEBUG: Crawled (200) <POST https://ecom.elko.ru/Acc ount/Login?ReturnUrl=%2fCatalog%2fCategory%2fSCO> (referer: https://ecom.elko.ru /Account/Login?ReturnUrl=%2fCatalog%2fCategory%2fSCO) 2016-12-17 23:46:22 [scrapy] INFO: Closing spider (finished) 2016-12-17 23:46:22 [scrapy] INFO: Dumping Scrapy stats: {'downloader/request_bytes': 2365, 'downloader/request_count': 5, 'downloader/request_method_count/GET': 3, 'downloader/request_method_count/POST': 2, 'downloader/response_bytes': 19527, 'downloader/response_count': 5, 'downloader/response_status_count/200': 4, 'downloader/response_status_count/302': 1, 'finish_reason': 'finished', 'finish_time': datetime.datetime(2016, 12, 17, 20, 46, 22, 105000), 'log_count/DEBUG': 6, 'log_count/INFO': 7, 'request_depth_max': 1, 'response_received_count': 4, 'scheduler/dequeued': 5, 'scheduler/dequeued/memory': 5, 'scheduler/enqueued': 5, 'scheduler/enqueued/memory': 5, 'start_time': datetime.datetime(2016, 12, 17, 20, 46, 21, 433000)} 2016-12-17 23:46:22 [scrapy] INFO: Spider closed (finished)
from livewires import games, color games.init(screen_width=640, screen_height=480, fps=50) import random class Pan(games.Sprite): image = games.load_image("pan.bmp") def __init__(self): super(Pan, self).__init__(image=Pan.image, x=games.mouse.x, bottom=games.screen.height - 40) self.score = games.Text(value=0, size=25, color=color.black, top=5, right=games.screen.width - 10) games.screen.add(self.score) def update(self): """ Move to mouse x position. """ self.x = games.mouse.x if self.left < 0: self.left = 0 if self.right > games.screen.width: self.right = games.screen.width self.check_catch() def check_catch(self): """ Check if catch pizzas. """ for pizza in self.overlapping_sprites: pizza.end_game() self.destroy() class Falling(games.Sprite): image = games.load_image("pizza.bmp") speed = 1 time_til_drop = 0 def __init__(self, x, y = 90): """ Initialize a Pizza object. """ super(Falling, self).__init__(image = Falling.image, x = x, y = y, dy = Falling.speed) def update(self): """ Decrease countdown or drop pizza and reset countdown. """ if self.time_til_drop > 0: self.time_til_drop -= 1 else: new_pizza = Falling(x=random.randrange(1, games.screen.width, 15)) games.screen.add(new_pizza) # set buffer to approx 30% of pizza height, regardless of pizza speed self.time_til_drop = int(new_pizza.height * 1.3 / Falling.speed) + 1 def end_game(self): """ End the game. """ end_message = games.Message(value = "Game Over", size = 90, color = color.red, x = games.screen.width/2, y = games.screen.height/2, lifetime = 5 * games.screen.fps, after_death = games.screen.quit) games.screen.add(end_message) def main(): """ Play the game. """ wall_image = games.load_image("wall.jpg", transparent = False) games.screen.background = wall_image pizza = Falling(x=0) games.screen.add(pizza) the_pan = Pan() games.screen.add(the_pan) games.mouse.is_visible = False games.screen.event_grab = True games.screen.mainloop() # start it up! main()
from __future__ import with_statement import os from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice def record(): with open('C:\op\text.txt') as inp : try: temp = inp.readlines() url = temp.pop(0) with open ('C:\op\text.txt','w') as out: for i in temp : out.write( i) return ''.join(['http:\\sait.ru', url] ) except IndexError: print('1') PACKAGE = 'com.android.chrome' ACTIVITY = 'com.google.android.apps.chrome.Main' COMPONENT = PACKAGE + "/" + ACTIVITY URI = record() device = MonkeyRunner.waitForConnection(0.1,'1777cda7') device.startActivity(component=COMPONENT, uri=URI) MonkeyRunner.sleep(15)
models.py class cost(models.Model): value = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True) begin_date = models.DateTimeField(default=timezone.now, blank=True) forms.py class form_cost(forms.ModelForm): class Meta: model = model.cost fields = ['value', 'begin_date'] view.py cost = model.cost.objects.get(id=int(request.POST['cost'])) form = form.form_cost(request.POST, instance=cost) if form.has_changed(): # Всегда True changed_data = form.changed_data
from __future__ import with_statement import os from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice def record(): with open('C:\op\link.txt') as inp : try: temp = inp.readlines() url = temp.pop(0) with open ('C:\op\link.txt','w') as out: for i in temp : out.write( i) return ''.join(['', url] ) except IndexError: print('1') PACKAGE = 'com.android.browser' ACTIVITY = '.BrowserActivity' COMPONENT = PACKAGE + "/" + ACTIVITY URI = record() device = MonkeyRunner.waitForConnection(0.1,'1777cda7') device.startActivity(component=COMPONENT, uri=URI)
import sys import os import time try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from com.dtmilano.android.viewclient import ViewClient vc = ViewClient(*ViewClient.connectToDeviceOrExit()) for bt in [ 'One', 'Two', 'Three', 'Four', 'Five' ]: b = vc.findViewWithText(bt) if b: (x, y) = b.getXY() print >>sys.stderr, "clicking b%s @ (%d,%d) ..." % (bt, x, y) b.touch() else: print >>sys.stderr, "b%s not found" % bt time.sleep(7) print >>sys.stderr, "bye"
bot = telebot.TeleBot(token) def send_message_to_manager(message, chat_id): bot.send_message(chat_id, message) @bot.message_handler(content_types=['text']) def handle_text(message): print (message.text) return message.text bot.polling()
class MainHandler(tornado.web.RequestHandler): def get(self): loader = tornado.template.Loader(".") self.write(loader.load("index.html").generate()) class WebSocketHandler(tornado.websocket.WebSocketHandler): def open(self): print ('connection opened...') self.write_message("The server says: 'Hello'. Connection was accepted.") def on_message(self, message): self.write_message("You said: " + message) telegramBots.send_message_to_manager(message) print ('received:', message) def on_close(self): print ('connection closed...') application = tornado.web.Application([ (r'/ws', WebSocketHandler), (r'/', MainHandler), (r"/(.*)", tornado.web.StaticFileHandler, {"path": "./resources"}), ]) if __name__ == "__main__": application.listen(9090) tornado.ioloop.IOLoop.instance().start()
from random import shuffle
def add_to_11(visible):
a = []
for x in range(len(visible)):
for y in range(len(visible)):
p=visible[x] + visible[y]
if p == 11:
a.append((x,y))
return tuple(a)
def jqk(visible):
a = []
for x in range(len(visible)):
if visible[x] in [1,11,12,13] :
a.append(x)
return tuple(a)
def play(deck, verbose):
d=shuffle(deck)
a = 'the quick brown fox jumps over the lazy dog' b = 'the quick brown dog jumps over the lazy fox'
['the quick brown','fox','jumps over the lazy','dog']
>>> difflib.SequenceMatcher(a=a,b=b).get_matching_blocks() [Match(a=0, b=0, size=16), Match(a=17, b=17, size=1), Match(a=19, b=19, size=21), Match(a=41, b=41, size=1), Match(a=43, b=43, size=0)] >>> a[0:16] 'the quick brown ' >>> a[17:18] 'o' >>> a[19:40] ' jumps over the lazy ' >>> a[41:42] 'o'
>>> a = 'the quick brown fox jumps over the lazy dog' >>> b = 'jumps over the lazy dog the quick brown fox' >>> difflib.SequenceMatcher(a=a,b=b).get_matching_blocks() [Match(a=20, b=0, size=23), Match(a=43, b=43, size=0)] >>> a[20:43] 'jumps over the lazy dog'
['jumps over the lazy dog', 'the quick brown fox']