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

    +2

    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
    import os
    import argparse
    import sys
    parser = argparse.ArgumentParser(description='tree')
    parser.add_argument('path',type=str,)
    parser.add_argument('-fo','--folders_only',action='store_true',)
    parser.add_argument('-i','--include',type=str,action='store',)
    parser.add_argument('-e','--exclude',type=str,action='store',)
    parser.add_argument('-a','--all',action='store_true',)
    parser.add_argument('-f','--full_name',action='store_true',)
    args = parser.parse_args()
    print(sys.argv[1])
    if args.include:
        itext = args.include
    if args.exclude:
        etext = args.exclude
    def divine_crutch(path, n):
        dir = os.listdir(path)
        for i in range(len(dir)):
            if os.path.isfile(path + '\\' + dir[i]):
                if not(args.folders_only):
                    if not(args.include and itext not in dir[i]):
                        if not(args.exclude and etext in dir[i]):
                            if not(not(args.all) and dir[i][0] == '.') and not(args.full_name):
                                print(n*' ', dir[i])
                            elif args.full_name and not(not(args.all) and dir[i][0] == '.'):
                                print(n*' ' ,path + '\\' + dir[i])
            if os.path.isdir(path + '\\' + dir[i]):
                if not(not(args.all) and dir[i][0] == '.') and not(args.full_name):
                    print(n*' ', dir[i])
                elif args.full_name and not(not(args.all) and dir[i][0] == '.'):
                    print(n*' ' ,path + '\\' + dir[i])
                n += 4
                divine_crutch(path + '\\' + dir[i], n)
                n -= 4
    divine_crutch(sys.argv[1], 4)

    Рекурсивный велосипед на костыльной тяге. Сей экземпляр является "аналогом системной утилиты tree под линукс". При подходящей фазе луны и выполнении условий ритуала чёрной магии, способен захавать 16 гигов оперативки и крашнуть систему. Прекрасный способ выстрелить в ногу на питоне. Достойное место в моей кунсткамере.

    Caladrius, 26 Октября 2017

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

    +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
    while (1):
        for iterator in range(len(posts)):
            # Для прозрачности вычислений
            time_post_a = datetime.now()
            time_post_a = int(time.mktime(time_post_a.timetuple()))
    
            time_post_b = posts[iterator]['time']
            time_post_b = int(time.mktime(time_post_b.timetuple()))
    
            # Выполнить действие, в случае, если "время пришло" по массиву posts
            if ((time_post_a - time_post_b) == 0):
                print ('Итератор: ' + str(iterator) + ', Новая публикация: ' + str(posts[iterator]['time']))
                time.sleep(1) # Если его убрать, то начинаются дикие пляски
                break

    Планировщик постов

    meridium, 26 Октября 2017

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

    +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
    23. 23
    24. 24
    25. 25
    26. 26
    from lxml import html
    import urllib
    import time
    import os
    
    last = ""
    img_path = "/tmp/avatar.png"
    
    while True:
    	try:
    		tree = html.parse(urllib.urlopen("http://govnokod.ru/comments"))
    
    		date = tree.xpath('/html/body/div/div[2]/ol/li[1]/div[1]/ul/li/div/p/a')[0].get('name')
    		if date != last:
    			last = date
    
    			image = tree.xpath('/html/body/div/div[2]/ol/li[1]/div[1]/ul/li/div/p/img')[0].get('src')
    			name = tree.xpath('/html/body/div/div[2]/ol/li[1]/div[1]/ul/li/div/p/strong/a')[0].text_content()
    			comment = tree.xpath('/html/body/div/div[2]/ol/li[1]/div[1]/ul/li/div/div')[0].text_content()
    			avatar = urllib.urlretrieve(image, img_path)
    			os.system('notify-send -i {} \'{}\' \'{}\''.format(img_path, name, comment.encode('utf-8')))
    
    		time.sleep(10)
    		
    	except Exception:
    		time.sleep(10)

    vistefan, 19 Октября 2017

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

    −7

    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
    import re
    
    def matrix():
        square = [[0 for x in range(7)] for x in range(7)]
        directions = ((1,0), (0,1), (-1,0), (0,-1))
        x, y, d = -1, 0, 0
        
        for i in range(49):
            while True:
                x1, y1 = x + directions[d][0], y + directions[d][1]
                
                if x1 >= 0 and x1 < 7 and y1 >= 0 and y1 < 7 and square[y1][x1] == 0:
                    x, y = x1, y1
                    break
                
                d = (d + 1) % 4
            
            square[y][x] = re.sub(r'\d', lambda n: ' ' * int(n.group()), '9de9mb8nv5yo4aol1rm')[i]
        
        return square
    
    print('\n'.join([''.join(line) for line in matrix()]).strip())

    по мативам http://govnokod.ru/23329#comment389918

    HACTEHbKA, 06 Сентября 2017

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

    −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
    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
    n = int(input())
    matrix = [[0] * n for i in range(n)]
    num = 1
    end = n
    start = 0
    while num != num**2:
        for i in range(start, end):
            if num == num**2:
                break
            for j in range(start, end):
                if num == num**2:
                    break
                matrix[i][j] = num
                num += 1
                if j + 1 == end:
                    for k in range(start+1, end):
                        if num == num**2:
                            break
                        matrix[k][j] = num
                        num += 1
                        if k + 1 == end:
                            for l in range(-end+1, -start):
                                if num == num**2:
                                    break
                                matrix[k][l] = num
                                num += 1
                                if l + 1 == start:
                                    for m in range(-end+1, -start-1):
                                        if num == num**2:
                                            break
                                        matrix[m][l] = num
                                        num += 1
            end -= 1
            start += 1
    for i in range(n):
        for j in range(n):
            print(matrix[i][j], end='\t')
        print()

    у меня на выходе только нули, не понимаю где нагадил,вот условие:

    Выведите таблицу размером n×n, заполненную числами от 1 до n**2 по спирали, выходящей из левого верхнего угла и закрученной по часовой стрелке, как показано в примере (здесь n=5):
    Sample Input:
    5
    Sample Output:
    1 2 3 4 5
    16 17 18 19 6
    15 24 25 20 7
    14 23 22 21 8
    13 12 11 10 9

    reznik, 05 Сентября 2017

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

    −9

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    class SimilarCardIsShown(ZenAndroidTest):
        def test_similar_show(self):
            cards = self.swipe_and_find_elements(By.ID, "com.yandex.zensample.app:id/card_title", 7)
            for card in cards:
                card.click()
                self.driver.back()
            assert self.driver.find_element_by_id("com.yandex.zensample.app:id/card_helper_sim_head"), "Нет похожих"

    хуй

    storvus, 05 Сентября 2017

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

    +3

    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
    N = int(input())
    S = []
    for i in range(N):
        S.append(list(map(float, input().split())))
    for i in range(len(S)):
        S[i][0], S[i][1] = S[i][1], S[i][0]
    S.sort()
    for x in range(N):
        for i in range(N-1):
            if S[i][0] == S[i+1][0]:
                if S[i][1] < S[i+1][1]:
                    S[i][1], S[i+1][1] = S[i+1][1], S[i][1]
    for i in range(N):
    print((str(round(S[i][1], 2))[:str(round(S[i][1], 2)).index('.')]+(str(round(S[i][1], 2))+'00000000')[str(round(S[i][1], 2)).index('.'):str(round(S[i][1], 2)).index('.')+3]),(str(round(S[i][0], 3))[:str(round(S[i][0], 3)).index('.')]+(str(round(S[i][0], 3))+'00000000')[str(round(S[i][0], 3)).index('.'):str(round(S[i][0], 3)).index('.')+4]))

    Нужно было дописать эту прогу во что бы то ни стало...

    Caladrius, 03 Сентября 2017

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

    +2

    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
    #!/usr/bin/env python
    
    import jinja2
    
    import contextlib
    import os.path
    import shutil
    import subprocess
    import sys
    import tempfile
    
    
    @contextlib.contextmanager
    def rm_dir(d):
        yield d
        shutil.rmtree(d)
    
    
    def main():
        if len(sys.argv) < 2:
            return
    
        if os.path.basename(sys.argv[1]) != "compile":
            subprocess.call(sys.argv[1:])
            return
    
        command = sys.argv[1:]
        preprocessed_files = []
    
        with rm_dir(tempfile.mkdtemp()) as tmpdir:
            print "Temp dir is", tmpdir
    
            while len(command) > 0 and not command[-1].startswith("-") and command[-1].endswith(".go"):
                tmpfile = os.path.join(tmpdir, str(len(command)) + ".go")
    
                with open(command[-1]) as input:
                    with open(tmpfile, "wb") as preprocessed:
                        print "Preprocess", command[-1], "into", tmpfile
                        preprocessed.write(jinja2.Template(input.read()).render())
    
                preprocessed_files.append(tmpfile)
                command.pop()
    
            subprocess.call(command + preprocessed_files)
    
    
    if __name__ == "__main__":
        main()

    Прикручиваем шаблонизатор jinja к го, чтобы копипастить с комфортом. Использовать так:

    go build -toolexec '/path/to/preprocess.py' package_na_go

    123123123, 22 Августа 2017

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    bool retval = true;
    
    while (someting) {
        ...
        if (retval) retval = sendDataInternal(data);
        else sendDataInternal(data);
    }
    
    return retval;

    Ничто не остановит бульдозер.

    bormand, 30 Июля 2017

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

    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
    a=int(input())
    b=int(input())
    c=int(input())
    d=int(input())
    x=a%2
    y=b%2
    z=c%2
    f=d%2
    if x==1 and y==1 and z==1 and f==1:
        print('YES')
    elif x==1 and y==1 and z==0 and f==0:
        print('YES')
    elif x==0 and y==0 and z==1 and f==1:
        print('YES')
    elif x==1 and y==0 and z==1 and f==0:
        print('YES')
    elif x==0 and y==1 and z==0 and f==1:
        print('YES')
    elif x==1 and y==1 and z==0 and f==1:
        print('NO')
    elif x==1 and y==1 and z==1 and f==0:
        print('NO')
    elif x==0 and y==0 and z==1 and f==0:
        print('NO')
    elif x==0 and y==0 and z==0 and f==1:
        print('NO')
    elif x==1 and y==0 and z==1 and f==1:
        print('NO')
    elif x==1 and y==0 and z==0 and f==1:
        print('YES')
    elif x==0 and y==1 and z==0 and f==0:
        print('NO')
    elif x==1 and y==0 and z==0 and f==1:
        print('YES')
    else: 
        print('YES')

    Откопал на Питонтьюторе.

    MaxLevs, 23 Июля 2017

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