Last active
November 10, 2023 05:38
-
-
Save goldengrape/30879ea2b7ca9e4819371ec18cfbc5e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# * write_to_file | |
# Writes text to a file. If file exists, appends the text at the end. If not, creates a new file. | |
# * del_file | |
# Deletes a file. | |
# * read_file | |
# Reads a file and returns the content. | |
# * add_task | |
# Adds a task to the task file. | |
# * view_tasks | |
# Views all the tasks in the task file. | |
# * task_done | |
# Deletes a task from the task file. | |
# * get_google_patent_url | |
# get fulltext url of a patent from google patents | |
# * get_google_patent_search_url | |
# get search url of a patent from google patents | |
# * get_pubmed_search_url | |
# get search url of a paper from pubmed | |
# * get_PMC_full_text_url | |
# get fulltext url of a paper from pubmed | |
# * get_PMC_search_url | |
# get search url of a paper from pubmed | |
# * read_text_from_file | |
# read length text from file from a start position | |
# * read_last_text_from_file | |
# read length text from file from the end of the file | |
def write_to_file(file_name, text_content): | |
with open(file_name, 'a', encoding='utf-8') as file: | |
file.write(text_content + "\n") | |
def del_file(filename): | |
import os | |
if os.path.exists(filename): | |
os.remove(filename) | |
return True | |
else: | |
print("The file does not exist") | |
return False | |
def read_file(filename): | |
with open(filename, 'r', encoding='utf-8') as file: | |
return file.read() | |
def add_task(task, task_file_name='tasks.txt'): | |
write_to_file(task_file_name, task) | |
def view_tasks(task_file_name='tasks.txt'): | |
return read_file(task_file_name) | |
def task_done(task, task_file_name='tasks.txt'): | |
tasks = read_file(task_file_name) | |
tasks = tasks.replace(task, '') | |
del_file(task_file_name) | |
write_to_file(task_file_name, tasks) | |
def get_google_patent_url(patentID): | |
return f"https://patents.google.com/patent/{patentID}" | |
def get_google_patent_search_url(search_text): | |
return f"https://patents.google.com/?q={search_text}" | |
def get_pubmed_search_url(search_text): | |
return f"https://pubmed.ncbi.nlm.nih.gov/?term={search_text}" | |
def get_PMC_full_text_url(PMCID): | |
return f"https://www.ncbi.nlm.nih.gov/pmc/articles/pmid/{PMCID}/" | |
def get_PMC_search_url(search_text): | |
return f"https://www.ncbi.nlm.nih.gov/pmc/?term={search_text}" | |
def read_text_from_file(filename,start_positon,length): | |
with open(filename, 'r', encoding='utf-8') as file: | |
file.seek(start_positon) | |
return file.read(length) | |
def read_last_text_from_file(filename, length): | |
with open(filename, 'r', encoding='utf-8') as file: | |
file.seek(-length, 2) | |
return file.read(length) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment