1. Python / Говнокод #25563

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    def da_pizda(update, context):
        global da_counter, pizda_counter
    
        text = update.message.text.split()
        text = [word.lower() for word in text]
    
        if 'дa' in text or 'da' in text or 'dа' in text:
            text.append('да')
        if 'пиздa' in text or 'pizda' in text or 'pizdа' in text or 'Πизда' in text:
            text.append('пизда')
    
        if 'да' in text:
            bot.send_message(chat_id=update.message.chat_id, text='пизда',
                             reply_to_message_id=update.message.message_id)
            pizda_counter += 1
        if 'пизда' in text:
            bot.send_message(chat_id=update.message.chat_id, text='да',
                             reply_to_message_id=update.message.message_id)
            da_counter += 1
    
        da_counter += update.message.text.split().count('да')
        pizda_counter += update.message.text.split().count('пизда')

    Бот, проверяющий наличие слов "да" и "пизда" в чате телеграма, и отвечающий соответственно.

    Umerenkov21, 23 Апреля 2019

    Комментарии (60)
  2. Python / Говнокод #25524

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    for i in for i in itertools.count():
        # ...
        if i >= x:
            break

    syoma, 08 Апреля 2019

    Комментарии (7)
  3. Python / Говнокод #25511

    0

    1. 1
    https://stackoverflow.com/questions/4233218/python-how-do-i-get-key-value-pairs-from-the-basehttprequesthandler-http-post-h

    Блядь, как всё сложно.
    Поэтому я за "PHP".

    OCETuHCKuu_nemyx, 04 Апреля 2019

    Комментарии (17)
  4. Python / Говнокод #25508

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    Change(models.model):
    
        def save(self, *args, **kwargs):
            is_need_to_add = False
    
            if not self.pk and self.package.type not in [Billing.TYPE_H, Billing.TYPE_F]:
                is_need_to_add = True
    
            super(Change, self).save(*args, **kwargs)
    
            if is_need_to_add:
                package = self.package
                package.done += self.delta
                if self.package.status == Billing.STATUS_IN_WORK and package.count_done >= package.count_wants:
                    package.status = Billing.STATUS_DONE
                    package.save()
    
                    title, id = self.package.company.title, self.package.company.id
                    leads, price = self.package.count_wants, self.package.price
                    mail.send("trololo")
    
                package.save()
                package.check_billing()

    Django ORM, внутри метода save() сразу и сохранение сущности в базу, и апдейт родительской сущности и mail нотификация менеджерам.

    facepalm, 04 Апреля 2019

    Комментарии (14)
  5. Python / Говнокод #25489

    0

    1. 1
    {% for item in object.items %}

    Внезапно выяснилось, что ебаная жинжа пытается не делает object['items'], а сначала ищет метод items().

    syoma, 31 Марта 2019

    Комментарии (36)
  6. Python / Говнокод #25484

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    # Чтение файла в "Python":
    with open("suka") as blyat:
        govno = blyat.read()
    
    // Чтение файла в "PHP":
    $govno = file_get_contents("suka");

    Почему нету способа в одну функцию, и нужно добавлять лишнюю вложенность?
    Это какой-то пиздец.

    OCETuHCKuu_nemyx, 28 Марта 2019

    Комментарии (49)
  7. Python / Говнокод #25459

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    with conn:
                cursor = conn.cursor()
                cursor.execute('UPDATE users SET creferals = creferals + 1 WHERE cid = ?', (inviter,))
                cursor.execute('INSERT INTO users VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
                               (datetime.strftime(datetime.now(),"%H:%M:%S %d.%m.%Y"), cid, username, 'main', 0, 0, 0, 0, 0, 0, 0, inviter, 'RUS'))
    conn.commit()

    Aristokraft, 21 Марта 2019

    Комментарии (75)
  8. Python / Говнокод #25451

    +2

    1. 1
    int(data[:4][::-1].encode('hex'),16)

    Кто-то не знал про struct

    syoma, 16 Марта 2019

    Комментарии (85)
  9. Python / Говнокод #25447

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    import sqlite3
    from bs4 import BeautifulSoup
    import requests, hashlib
    from io import open as iopen
    from urlparse import urlsplit
    
    def md5sum(filename, blocksize=65536):
    	hash = hashlib.md5()
    	with open(filename, "rb") as f:
    		for block in iter(lambda: f.read(blocksize), b""):
    			hash.update(block)
    	return hash.hexdigest()
    
    def parse_image_url(url):
    	html_doc = requests.get(url).text
    	soup = BeautifulSoup(html_doc, 'html.parser')
    	first = soup.find(class_='postContainer')
    	two = first.find_all('img')
    	requests_image(two[1].get('src'))
    
    def unic_check(file_name):
    	check_sum = md5sum(file_name)
    	if c.execute("SELECT * FROM sums WHERE sum = '%s'" % check_sum) != None:
    		cur.close()
    		conn.close()
    		return
    	else:
    		c.execute("INSERT INTO sums VALUES (%s)" % check_sum)
    		c.commit()
    		cur.close()
    		conn.close()
    		return
    
    def requests_image(file_url):
    	suffix_list = ['jpg', 'gif', 'png', 'tif', 'svg',]
    	file_name =  urlsplit(file_url)[2].split('/')[-1]
    	file_suffix = file_name.split('.')[1]
    	i = requests.get(file_url)
    	if file_suffix in suffix_list and i.status_code == requests.codes.ok:
    		with iopen(file_name, 'wb') as file:
    			file.write(i.content)
    	else:
    		return False
    	unic_check(file_name)
    
    def main():
    	Anime_types = ['http://anime.reactor.cc/tag/Anime+%D0%9D%D1%8F%D1%88%D0%B8', 'http://anime.reactor.cc/tag/Anime+Cosplay', 'http://anime.reactor.cc/tag/Anime+%D0%9A%D0%BE%D0%BC%D0%B8%D0%BA%D1%81%D1%8B', 'http://anime.reactor.cc/tag/Anime+Art']
    	global conn
    	global c
    	conn = sqlite3.connect('anime.db')
    	c = conn.cursor()
    	for x in Anime_types:
    		parse_image_url(x)
    		
    if __name__ == "__main__":
    	main()

    marataziat, 13 Марта 2019

    Комментарии (20)
  10. Python / Говнокод #25410

    0

    1. 1
    Мне кажется или в тройке input(str) не дружит в юникоде в str?

    syoma, 26 Февраля 2019

    Комментарии (22)