Browse Source

Removed migration scripts

database_migration
parent
commit
22a3d9021e
No known key found for this signature in database GPG Key ID: 2D0E48C8FAA7D9A1
8 changed files with 0 additions and 515 deletions
  1. +0
    -74
      chapters/migrate.py
  2. +0
    -74
      edu/migrate.py
  3. +0
    -83
      leadership/migrate.py
  4. +0
    -64
      news/migrate.py
  5. +0
    -54
      resolutions/migrate.py
  6. +0
    -55
      resources/carry-laws/migrate.py
  7. +0
    -55
      resources/hunting-laws/migrate.py
  8. +0
    -56
      resources/migrate.py

+ 0
- 74
chapters/migrate.py View File

@ -1,74 +0,0 @@
# Copyright (C) 2021 Socialist Rifle Association
#
# This file is part of website.
#
# website is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# website is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with website. If not, see <http://www.gnu.org/licenses/>.
import json
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, sessionmaker
from sqlalchemy import create_engine
# Support function
def value_or_default(object, value, default=""):
return object[value] if value in object else default
Base = declarative_base()
# Define chapter class
class Chapter(Base):
__tablename__ = 'chapter'
id = Column(Integer, primary_key=True, autoincrement=True)
state = Column(String(2))
name = Column(String(250))
logo = Column(String(250))
email = Column(String(250))
website = Column(String(250))
twitter = Column(String(250))
facebook = Column(String(250))
instagram = Column(String(250))
phone = Column(String(250))
engine = create_engine('sqlite:///../website_database.db')
# Create tables in SQLite database
Base.metadata.create_all(engine)
# Open the database file
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
# Load JSON file
with open("chapters.json", "r") as file:
states = json.load(file)
# Add chapters to database
for state in states:
for chapter in states[state]:
print(chapter["name"])
session.add(Chapter(
state = state,
name = chapter["name"],
logo = chapter["logo"] if chapter["logo"] != "default" else "",
email = value_or_default(chapter["social"], "email"),
phone = value_or_default(chapter["social"], "phone"),
website = value_or_default(chapter["social"], "website"),
twitter = value_or_default(chapter["social"], "twitter"),
facebook = value_or_default(chapter["social"], "facebook"),
instagram = value_or_default(chapter["social"], "instagram")
))
# Write data to database
session.commit()

+ 0
- 74
edu/migrate.py View File

@ -1,74 +0,0 @@
# Copyright (C) 2021 Socialist Rifle Association
#
# This file is part of website.
#
# website is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# website is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with website. If not, see <http://www.gnu.org/licenses/>.
import json
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, sessionmaker
from sqlalchemy import create_engine
# Support function
def value_or_default(object, value, default=""):
return object[value] if value in object else default
Base = declarative_base()
# Define section and item classes
class Section(Base):
__tablename__ = "edu_section"
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(250))
class Item(Base):
__tablename__ = 'edu_item'
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(250))
section = relationship(Section)
section_name = Column(String(250), ForeignKey('edu_section.name'))
type = Column(String(250))
filename = Column(String(250))
engine = create_engine('sqlite:///../website_database.db')
# # Create tables in SQLite database
Base.metadata.create_all(engine)
# # Open the database file
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
# Load JSON file
with open("content.json", "r") as file:
sections = json.load(file)
# Add chapters to database
for section in sections:
section_object = Section(
name = section["name"]
)
session.add(section_object)
for item in section["content"]:
print(item["name"])
session.add(Item(
name = value_or_default(item, "name", "Untitled"),
section = section_object,
type = value_or_default(item, "type", "document"),
filename = item["filename"]
))
# Write data to database
session.commit()

+ 0
- 83
leadership/migrate.py View File

@ -1,83 +0,0 @@
# Copyright (C) 2021 Socialist Rifle Association
#
# This file is part of website.
#
# website is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# website is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with website. If not, see <http://www.gnu.org/licenses/>.
import json
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, sessionmaker
from sqlalchemy import create_engine
from glob import glob
from pathlib import Path
import re
# Support function
def value_or_default(object, value, default=""):
return object[value] if value in object else default
Base = declarative_base()
# Define section and item classes
class Section(Base):
__tablename__ = "leadership_department"
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(250))
class Item(Base):
__tablename__ = 'leadership_person'
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(250))
section = relationship(Section)
section_name = Column(String(250), ForeignKey('leadership_department.name'))
pronouns = Column(String(250))
title = Column(String(250))
email = Column(String(250))
bio = Column(String(250))
engine = create_engine('sqlite:///../website_database.db')
# # Create tables in SQLite database
Base.metadata.create_all(engine)
# # Open the database file
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
# Load markdown files
for file in glob("content/*.md"):
department_name = Path(file).stem
current_department = Section(name=department_name)
# session.add(current_department)
with open(file, "r") as f:
for person in f.read().split('---'):
lines = [line for line in person.split('\n') if line != ""]
emails = re.findall(r'[\w\.-][email protected][\w\.-]+', lines[3])
if len(emails) == 0:
emails = ""
else:
emails = emails[0]
session.add(Item(
name = lines[0][2:],
section = current_department,
pronouns = lines[1][1:-1],
title = lines[2][2:-2],
email = emails,
bio = lines[4] if len(lines) >= 5 else ""
))
# Write data to database
session.commit()

+ 0
- 64
news/migrate.py View File

@ -1,64 +0,0 @@
# Copyright (C) 2021 Socialist Rifle Association
#
# This file is part of website.
#
# website is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# website is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with website. If not, see <http://www.gnu.org/licenses/>.
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Text
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, sessionmaker
from sqlalchemy import create_engine
from glob import glob
import json
import datetime
Base = declarative_base()
class Story(Base):
__tablename__ = "news_story"
id = Column(Integer, primary_key=True, autoincrement=True)
title = Column(String(250))
subtitle = Column(String(250))
author = Column(String(250))
date = Column(DateTime())
thumbnail = Column(String(250))
content = Column(Text())
engine = create_engine('sqlite:///../website_database.db')
# # Create tables in SQLite database
Base.metadata.create_all(engine)
# # Open the database file
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
# Load news files
stories = glob("stories/*")
stories.sort()
for story in stories:
meta = json.load(open(f"{story}/meta.json", "r"))
story_content = open(f"{story}/content.md", "r").read()
session.add(Story(
title = meta["title"],
subtitle = meta["subtitle"],
author = meta["author"],
date = datetime.datetime.strptime(meta["date"], '%B %d, %Y %I:%M %p'),
thumbnail = meta["thumb"],
content = bytes(story_content, encoding="utf-8")
))
# Write data to database
session.commit()

+ 0
- 54
resolutions/migrate.py View File

@ -1,54 +0,0 @@
# Copyright (C) 2021 Socialist Rifle Association
#
# This file is part of website.
#
# website is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# website is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with website. If not, see <http://www.gnu.org/licenses/>.
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Text
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, sessionmaker
from sqlalchemy import create_engine
from glob import glob
import json
import datetime
Base = declarative_base()
class Resolution(Base):
__tablename__ = "resolution"
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(250))
date = Column(DateTime())
file = Column(String(250))
engine = create_engine('sqlite:///../website_database.db')
# # Create tables in SQLite database
Base.metadata.create_all(engine)
# # Open the database file
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
# Load resolutions
for resolution in json.load(open("resolutions.json", "r")):
session.add(Resolution(
name = resolution["name"],
date = datetime.datetime.strptime(resolution["date"], '%Y/%m'),
file = resolution["file"]
))
# Write data to database
session.commit()

+ 0
- 55
resources/carry-laws/migrate.py View File

@ -1,55 +0,0 @@
# Copyright (C) 2021 Socialist Rifle Association
#
# This file is part of website.
#
# website is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# website is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with website. If not, see <http://www.gnu.org/licenses/>.
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Text, Boolean
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, sessionmaker
from sqlalchemy import create_engine
from glob import glob
import json
import datetime
Base = declarative_base()
class Resource(Base):
__tablename__ = "resources_statelaw"
id = Column(Integer, primary_key=True, autoincrement=True)
state = Column(String(250))
page = Column(String(250))
url = Column(String(250))
engine = create_engine('sqlite:///../../website_database.db')
# # Create tables in SQLite database
Base.metadata.create_all(engine)
# # Open the database file
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
# Load resolutions
data = json.load(open("content.json", "r"))
for resolution in data:
session.add(Resource(
state = resolution,
page = "carry-laws",
url = data[resolution]
))
# Write data to database
session.commit()

+ 0
- 55
resources/hunting-laws/migrate.py View File

@ -1,55 +0,0 @@
# Copyright (C) 2021 Socialist Rifle Association
#
# This file is part of website.
#
# website is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# website is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with website. If not, see <http://www.gnu.org/licenses/>.
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Text, Boolean
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, sessionmaker
from sqlalchemy import create_engine
from glob import glob
import json
import datetime
Base = declarative_base()
class Resource(Base):
__tablename__ = "resources_statelaw"
id = Column(Integer, primary_key=True, autoincrement=True)
state = Column(String(250))
page = Column(String(250))
url = Column(String(250))
engine = create_engine('sqlite:///../../website_database.db')
# # Create tables in SQLite database
Base.metadata.create_all(engine)
# # Open the database file
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
# Load resolutions
data = json.load(open("content.json", "r"))
for resolution in data:
session.add(Resource(
state = resolution,
page = "hunting-laws",
url = data[resolution]
))
# Write data to database
session.commit()

+ 0
- 56
resources/migrate.py View File

@ -1,56 +0,0 @@
# Copyright (C) 2021 Socialist Rifle Association
#
# This file is part of website.
#
# website is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# website is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with website. If not, see <http://www.gnu.org/licenses/>.
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Text, Boolean
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, sessionmaker
from sqlalchemy import create_engine
from glob import glob
import json
import datetime
Base = declarative_base()
class Resource(Base):
__tablename__ = "resources_item"
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(250))
icon = Column(String(250))
is_file = Column(Boolean())
url = Column(String(250))
engine = create_engine('sqlite:///../website_database.db')
# # Create tables in SQLite database
Base.metadata.create_all(engine)
# # Open the database file
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
# Load resolutions
for resolution in json.load(open("content.json", "r")):
session.add(Resource(
name = resolution["name"],
icon = resolution["icon"],
is_file = "https://" in resolution["url"],
url = resolution["url"].split("/")[-1] if "https://" in resolution["url"] else resolution["url"]
))
# Write data to database
session.commit()

Loading…
Cancel
Save