Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
U
url_shorter_docker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jonas Leder
url_shorter_docker
Commits
7df2c960
Commit
7df2c960
authored
Oct 6, 2019
by
Jonas Leder
Browse files
Options
Downloads
Patches
Plain Diff
Added import and some changes to docker-compose
parent
7dc9ec66
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+2
-0
2 additions, 0 deletions
.gitignore
Dockerfile
+8
-4
8 additions, 4 deletions
Dockerfile
import.py
+37
-0
37 additions, 0 deletions
import.py
main.py
+1
-1
1 addition, 1 deletion
main.py
with
48 additions
and
5 deletions
.gitignore
+
2
−
0
View file @
7df2c960
db/urls.db
db/urls.db
import.csv
This diff is collapsed.
Click to expand it.
Dockerfile
+
8
−
4
View file @
7df2c960
...
@@ -12,12 +12,16 @@ LABEL Name=url_shorter Version=1.0.1
...
@@ -12,12 +12,16 @@ LABEL Name=url_shorter Version=1.0.1
EXPOSE
5000
EXPOSE
5000
WORKDIR
/app
WORKDIR
/app
ADD
. /app
ADD
./static /app/static
ADD
./templates /app/templates
COPY
import.py /app/import.py
COPY
main.py /app/main.py
#
RUN apt update
RUN
apt update
#
RUN apt upgrade -y
RUN
apt upgrade
-y
RUN
pip
install
pipreqs
RUN
pip
install
pipreqs
RUN
pipreqs
.
--force
RUN
pipreqs
.
--force
RUN
python3
-m
pip
install
-r
requirements.txt
RUN
python3
-m
pip
install
-r
requirements.txt
RUN
date
>
builddate.txt
RUN
date
>
builddate.txt
CMD
["python3", "main.py"]
ENTRYPOINT
python3 main.py
This diff is collapsed.
Click to expand it.
import.py
0 → 100644
+
37
−
0
View file @
7df2c960
import
sqlite3
import
os
def
table_check
():
create_table
=
"""
CREATE TABLE WEB_URL(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
LONG_URL TEXT NOT NULL, SHORT_URL TEXT NOT NULL
);
"""
with
sqlite3
.
connect
(
'
db/urls.db
'
)
as
conn
:
cursor
=
conn
.
cursor
()
try
:
#Try making the database structure, if fails Database was already created.
cursor
.
execute
(
create_table
)
except
sqlite3
.
OperationalError
:
pass
table_check
()
with
sqlite3
.
connect
(
'
db/urls.db
'
)
as
conn
:
cursor
=
conn
.
cursor
()
try
:
file
=
open
(
"
import.csv
"
,
"
r
"
).
readlines
()
except
:
print
(
"
no file for import found
"
)
exit
()
entries
=
len
(
file
)
counter
=
1
for
lines
in
file
:
print
(
"
Importing
"
+
str
(
counter
)
+
"
from
"
+
str
(
entries
))
SHORT_URL
=
lines
.
split
(
"
;
"
)[
0
].
replace
(
"
\n
"
,
""
).
replace
(
"
\r
"
,
""
)
LONG_URL
=
lines
.
split
(
"
;
"
)[
1
].
replace
(
"
\n
"
,
""
).
replace
(
"
\r
"
,
""
)
res
=
cursor
.
execute
(
'
INSERT INTO WEB_URL (LONG_URL, SHORT_URL) VALUES (?, ?)
'
,
[
LONG_URL
,
SHORT_URL
]
)
counter
=
counter
+
1
os
.
system
(
"
exit
"
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
main.py
+
1
−
1
View file @
7df2c960
...
@@ -59,7 +59,7 @@ def home():
...
@@ -59,7 +59,7 @@ def home():
except
Exception
as
e
:
except
Exception
as
e
:
pass
pass
if
not
already_used
:
#If
noone used the short link
before, insert the
data
in the Database.
if
not
already_used
:
#If
short link wasn't used
before, insert the
link
in the Database.
res
=
cursor
.
execute
(
res
=
cursor
.
execute
(
'
INSERT INTO WEB_URL (LONG_URL, SHORT_URL) VALUES (?, ?)
'
,
'
INSERT INTO WEB_URL (LONG_URL, SHORT_URL) VALUES (?, ?)
'
,
[
url
,
request
.
form
.
get
(
'
domain
'
)
+
"
/
"
+
request
.
form
.
get
(
'
short
'
)]
[
url
,
request
.
form
.
get
(
'
domain
'
)
+
"
/
"
+
request
.
form
.
get
(
'
short
'
)]
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment