diff options
| -rw-r--r-- | database.py | 16 | ||||
| -rw-r--r-- | insinuations.py | 19 | ||||
| -rw-r--r-- | requirements.txt | 1 | ||||
| -rw-r--r-- | static/style.css | 16 | ||||
| -rw-r--r-- | templates/template.html.j2 | 4 | 
5 files changed, 46 insertions, 10 deletions
diff --git a/database.py b/database.py index 26d2683..53d755e 100644 --- a/database.py +++ b/database.py @@ -120,6 +120,9 @@ class PayGapDatabase:              self.__connection.commit()              return self.__connection +    def _wrap_percent(self, word): +        return "%%%s%%" % (word) +      def append_sic_sections(self, section_id, description):          # print("Section ID: '%s', Description: '%s'" % (section_id, description))          with self.__connection.cursor() as cursor: @@ -204,3 +207,16 @@ class PayGapDatabase:                  cursor.execute("SELECT * FROM sic WHERE sic_code = %s", (sic, ))                  if cursor.fetchone() != None:                      cursor.execute("INSERT INTO employer_sic VALUES (%s, %s);", (company_number, sic)) + +    def search_company(self, company_prefix): +        with self.__connection.cursor() as cursor: +            cursor.execute(""" +            SELECT name, company_number FROM employer  +            WHERE name LIKE '%s' OR current_name LIKE '%s' +            LIMIT 10; +            """ % ( +                self._wrap_percent(company_prefix), +                self._wrap_percent(company_prefix) +            )) + +            return [(i[0].title(), i[1]) for i in cursor.fetchall()] diff --git a/insinuations.py b/insinuations.py index a94607b..282b93e 100644 --- a/insinuations.py +++ b/insinuations.py @@ -70,13 +70,12 @@ def lookup_company(company_number):      return company  if __name__ == "__main__": -    # if not os.path.exists(".docker"): -    #     import dotenv -    #     dotenv.load_dotenv(dotenv_path = "db.env") -    #     host = "srv.home" -    # else: -    #     host = "db" - -    # with database.PayGapDatabase(host = host) as db: -    #     get_sics(db) -    print(lookup_company("02838054"))
\ No newline at end of file +    if not os.path.exists(".docker"): +        import dotenv +        dotenv.load_dotenv(dotenv_path = "db.env") +        host = "localhost" +    else: +        host = "db" + +    with database.PayGapDatabase(host = host) as db: +        print(db.search_company("University"))
\ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 2eff776..5e5339e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ pymysql  lxml  python-dotenv  flask +requests diff --git a/static/style.css b/static/style.css index be2f299..c527b3a 100644 --- a/static/style.css +++ b/static/style.css @@ -28,6 +28,22 @@ aside {      border-left-style: groove; */  } +input[type=search] { +    padding: 3px 5px; +    box-sizing: border-box; +    border: 2px solid black; +    width: 100%; +} + +aside form input[type=submit] { +    margin-top: 3px; +    width: 100%; +    background-color: black; +    color: white; +    border-radius: 5px; +    border: 2px solid black; +} +  #main_content {      padding-left: 2.5%;      padding-right: 2.5; diff --git a/templates/template.html.j2 b/templates/template.html.j2 index 1fb238d..89539d2 100644 --- a/templates/template.html.j2 +++ b/templates/template.html.j2 @@ -30,6 +30,10 @@      </header>      <aside> +        <form id="searchform"> +            <input type="search" value="Search..."> +            <input type="submit" value="Search"> +        </form>          <h4>Filter...</h4>      </aside>  | 
