1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. Python / Говнокод #23190

    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
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    class Cell:
        def __init__(self, row_id, column_id):
            """Описание ячейки в матрице"""
            """Определение первой буквы в ячейке"""
            if row_id == 0:
                self.cell_letter_1 = 'A'
            elif row_id == 1:
                self.cell_letter_1 = 'K'
            elif row_id == 2:
                self.cell_letter_1 = 'Q'
            elif row_id == 3:
                self.cell_letter_1 = 'J'
            elif row_id == 4:
                self.cell_letter_1 = 'T'
            elif row_id == 5:
                self.cell_letter_1 = '9'
            elif row_id == 6:
                self.cell_letter_1 = '8'
            elif row_id == 7:
                self.cell_letter_1 = '7'
            elif row_id == 8:
                self.cell_letter_1 = '6'
            elif row_id == 9:
                self.cell_letter_1 = '5'
            elif row_id == 10:
                self.cell_letter_1 = '4'
            elif row_id == 11:
                self.cell_letter_1 = '3'
            elif row_id == 12:
                self.cell_letter_1 = '2'
            """Определение второй буквы в ячейке"""
            if column_id == 0:
                self.cell_letter_2 = 'A'
            elif column_id == 1:
                self.cell_letter_2 = 'K'
            elif column_id == 2:
                self.cell_letter_2 = 'Q'
            elif column_id == 3:
                self.cell_letter_2 = 'J'
            elif column_id == 4:
                self.cell_letter_2 = 'T'
            elif column_id == 5:
                self.cell_letter_2 = '9'
            elif column_id == 6:
                self.cell_letter_2 = '8'
            elif column_id == 7:
                self.cell_letter_2 = '7'
            elif column_id == 8:
                self.cell_letter_2 = '6'
            elif column_id == 9:
                self.cell_letter_2 = '5'
            elif column_id == 10:
                self.cell_letter_2 = '4'
            elif column_id == 11:
                self.cell_letter_2 = '3'
            elif column_id == 12:
                self.cell_letter_2 = '2'
            """Установка порядка отойбражения 1-й и 2-й буквы в ячейке"""
            if row_id == 0:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 1 and column_id >= 2:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 2 and column_id >= 3:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 3 and column_id >= 4:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 4 and column_id >= 5:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 5 and column_id >= 6:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 6 and column_id >= 7:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 7 and column_id >= 8:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 8 and column_id >= 9:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 9 and column_id >= 10:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 10 and column_id >= 11:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 11 and column_id == 12:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            else:
                self.cell_text = self.cell_letter_2 + self.cell_letter_1

    http://python.su/forum/topic/33195/?page=1#post-181430

    FishHook, 17 Июля 2017

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

    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
    57. 57
    58. 58
    59. 59
    60. 60
    import csv
    import json
    
    import requests
    
    from io import StringIO
    
    from lxml import etree
    
    
    class DayPicParser(object):
        url = 'урл_до_сайта'
    
        def get_info(self):
            handler = open('daypic.csv', 'w+')
            page = 1
            rows = []
            tags = set()
            while page <= 1077:
                response = requests.get('{}/page/{}'.format(self.url, page))
                response.connection.close()
                parser = etree.HTMLParser()
                tree = etree.parse(StringIO(response.text), parser)
                posts = tree.xpath('//div[@class="posts"]/div[@class="post"]')
                for i, post in enumerate(posts):
                    title = post.find('./h2/a')
                    link_to_fulltext = title.attrib['href']
    
                    short_text = post.find('./div[@class="text"]//p[1]')
                    response = requests.get(link_to_fulltext)
                    full_parser = etree.HTMLParser()
                    full_tree = etree.parse(StringIO(response.text), full_parser)
                    full_post = full_tree.xpath('//div[@class="text"]//p')
    
                    main_image = None
                    full_text = []
                    for inner in full_post:
                        if inner.find('.//noindex') is not None:
                            continue
                        if inner.find('.//img') is not None:
                            src = inner.find('.//img').attrib['src']
                            if not main_image:
                                main_image = src
                            full_text.append({'image': src})
                        for paragraph in etree.tostring(inner, method="text", encoding='utf-8').decode('utf-8').strip().split("\n"):
                            if paragraph:
                                full_text.append({'text': paragraph})
                    rows.append({'title': title.text.strip(),
                                 'preview': main_image if main_image else '',
                                 'short_text': short_text.text.strip(),
                                 'full_text': full_text})
                    print('Post {} of {}'.format(i, len(posts)))
                page += 1
                print(page)
            handler.write(json.dumps(rows))
            handler.close()
            print(tags)
    
    
    DayPicParser().get_info()

    storvus, 10 Июля 2017

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

    +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
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    class StreamRailBase:
        __metaclass__ = ABCMeta
    
        def __init__(self): pass
    
        # @abstractmethod
        # def create_connection(self): pass
        #
        # @abstractmethod
        # def send_to_sr(self, method, path, params=None): pass
    
        # @abstractmethod
        # def get_advertisers(self): pass
        #
        # @abstractmethod
        # def get_targeting_conditions(self, env, geos, os, size, white_list, black_list): pass
        #
        # @abstractmethod
        # def create_ad_source(self, name, price, partner, tag_url, env, geos, os, size, req_cap, imp_cap, white_list=None, black_list=None): pass
        #
        # @abstractmethod
        # def create_sr_tag(self, tag_instance): pass
        #
        # @abstractmethod
        # def create_domain_list(self, f, list_type, adsource_name): pass
        #
        # @abstractmethod
        # def activate_adsource(self, adsource_id): pass
        #
        # @abstractmethod
        # def deactivate_adsource(self, adsource_id): pass
        #
        # @abstractmethod
        # def set_caps(self, params, new_req_cap, new_imp_cap): pass
        #
        # @abstractmethod
        # def set_geos(self, params, new_geos): pass
        #
        # @abstractmethod
        # def edit_domain_list(self, f, list_id): pass
        #
        # @abstractmethod
        # def set_list(self, params, new_list, list_type): pass
        #
        # @abstractmethod
        # def set_size(self, params, size): pass
        #
        # @abstractmethod
        # def edit_adsource(self, tag_instance, form_data): pass
        #
        # @abstractmethod
        # def create_new_partner(self, name): pass
        #
        # @abstractmethod
        # def sync_tag(self, tag_instance): pass
        #
        # @abstractmethod
        # def add_new_tag_to_template(self, tag_name, price, tag_id, adv_id): pass

    В человеке умер рахитектор, и в отчаянии, он закомитил эту хуйню в мастер.

    wvxvw, 09 Июля 2017

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

    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
    # returns yesterday reports
        def get_yesterday_reports(self):
            pass
    
        def get_waterfall_sources(self, wf_id, active_only=False):
            # TODO: check if meta property is equal to the number of items in the array
            # return test.mock_waterfall_sources.get_sources()
            status = '1' if active_only else urllib.quote('0,1')  # '0%2C1&'
            self.get_auth_token()
            encoded = urllib.urlencode({'authorization': self.token})
            url = BASE_URL + "/waterfall-ad-sources?advertiser=&itemsPerPage=9999&name=&page=1&sortAsc=true&sortBy=tier&status={}&tier=&waterfall={}&{}" \
                .format(status, wf_id, encoded)
    
            retries = 1
            while retries <= 3:
                response = requests.get(url)
                if response.status_code == 200:
                    break
                else:
                    logging.error('Failed GET request to StreamRail, status code {}, {} retries'
                                  .format(response.status_code, retries))
                retries += 1
    
            assert response.status_code == 200
            try:
                data = simplejson.loads(response.content)
                waterfall_sources = data['waterfallAdSources']
                assert int(data['meta']['total']) == len(waterfall_sources)
                return waterfall_sources
            except:
                logging.exception("Could not load ad sources for waterfall {} from StreamRail:\n"
                                  "{}".format(wf_id, response.headers))
                raise

    Хотя, с другой стороны, все эти рекламораспространители так выглядят. Но тут просто кучно так получилось.

    wvxvw, 06 Июля 2017

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

    +4

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    def do_creaprim(self, mesh, objname, addondir):
    	
    	global message
    	
    	objname = objname.replace(".", "")
    	objname = objname.replace(" ", "_")
    	bm = bmesh.new()
    	bm.from_mesh(mesh)	  
    	
    	
    	try:
    		txt = bpy.data.texts[str.lower("add_mesh_" + objname) + ".py"]
    		txt.clear()
    	except:
    		txt = bpy.data.texts.new("add_mesh_" + str.lower(objname) + ".py")
    	
    	strlist = []
    	strlist.append("bl_info = {\n")
    	strlist.append("\"name\": \"" + objname + "\", \n")
    	strlist.append("\"author\": \"Gert De Roost\",\n")
    	strlist.append("\"version\": (1, 0, 0),\n")
    	strlist.append("\"blender\": (2, 65, 0),\n")
    	strlist.append("\"location\": \"Add > Mesh\",\n")
    	strlist.append("\"description\": \"Create " + objname + " primitive.\",\n")
    	strlist.append("\"warning\": \"\",\n")
    	strlist.append("\"wiki_url\": \"\",\n")
    	strlist.append("\"tracker_url\": \"\",\n")
    	strlist.append("\"category\": \"Add Mesh\"}\n")
    	strlist.append("\n")
    	strlist.append("\n") 
    	strlist.append("if \"bpy\" in locals():\n")
    	strlist.append("	   import imp\n")
    	strlist.append("\n")
    	strlist.append("\n")
    	strlist.append("import bpy\n")
    	strlist.append("import bmesh\n")
    	strlist.append("import math\n")
    	strlist.append("from mathutils import *\n")
    	strlist.append("\n")
    	strlist.append("\n")
    	strlist.append("\n")
    	strlist.append("\n")
    	strlist.append("class " + objname + "(bpy.types.Operator):\n")
    	strlist.append("	bl_idname = \"mesh." + str.lower(objname) + "\"\n")
    	strlist.append("	bl_label = \"" + objname + "\"\n")
    	strlist.append("	bl_options = {\'REGISTER\', \'UNDO\'}\n")
    	strlist.append("	bl_description = \"add " + objname + " primitive\"\n")
    	strlist.append("\n")
    	strlist.append("	def invoke(self, context, event):\n")
    	strlist.append("\n")
    	strlist.append("		mesh = bpy.data.meshes.new(name=\"" + objname + "\")\n")
    	strlist.append("		obj = bpy.data.objects.new(name=\"" + objname + "\", object_data=mesh)\n")
    	strlist.append("		scene = bpy.context.scene\n")
    	strlist.append("		scene.objects.link(obj)\n")
    	strlist.append("		obj.location = scene.cursor_location\n")
    	strlist.append("		bm = bmesh.new()\n")
    	strlist.append("		bm.from_mesh(mesh)\n")
    	strlist.append("\n")
    	strlist.append("		idxlist = []\n")
    	posn = 0
    	strlist.append("		vertlist = [")
    	for v in bm.verts:
    		if posn > 0:
    			strlist.append(", ")
    		posn += 1
    		strlist.append(str(v.co[:]))
    	strlist.append("]\n")	 
    	strlist.append("		for co in vertlist:\n")
    	strlist.append("			v = bm.verts.new(co)\n")
    	strlist.append("			bm.verts.index_update()\n")
    	strlist.append("			idxlist.append(v.index)\n")
    	posn = 0
    	strlist.append("		edgelist = [")
    	for e in bm.edges:
    		if posn > 0:
    			strlist.append(", ")
    		posn += 1
    		strlist.append("[" + str(e.verts[0].index) + ", " + str(e.verts[1].index) + "]")
    	strlist.append("]\n")	 
    	strlist.append("		for verts in edgelist:\n")
    	strlist.append("			try:\n")
    	strlist.append("				bm.edges.new((bm.verts[verts[0]], bm.verts[verts[1]]))\n")
    	strlist.append("			except:\n")
    	strlist.append("				pass\n")
    	posn1 = 0
    	strlist.append("		facelist = [(")
    	for f in bm.faces:
    		if posn1 > 0:
    			strlist.append(", (")
    		posn1 += 1
    		posn2 = 0
    		for v in f.verts:
    			if posn2 > 0:
    				strlist.append(", ")
    			strlist.append(str(v.index))
    			posn2 += 1
    		strlist.append(")")
    	strlist.append("]\n")	 
    	strlist.append("		bm.verts.ensure_lookup_table()\n")
    	strlist.append("		for verts in facelist:\n")

    Залил вам отборного

    Skarn, 30 Июня 2017

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