-
Notifications
You must be signed in to change notification settings - Fork 9
/
unitpedialib.py
66 lines (51 loc) · 8.82 KB
/
unitpedialib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# The unit information list 'unitpedia' has been created by Wendelstein7, https://github.com/Wendelstein7
# Licenced under: MIT License, Copyright (c) 2018 Wendelstein7 and ficolas2
import discord
import re
def lookup(search):
for art in InformationArticles.articles:
if art.regexSearch.fullmatch(search):
return art.embed
return "notfound"
#TODO: Add code that finds the search keyword using the regex in the information articles list. Should return the 'embed' of the found InformationArticle.
class InformationArticle:
def __init__( self, regexsearch, longname, shortname, category, origin, history, definition, isSI, wiki ):
self.regexSearch = re.compile(regexsearch, re.IGNORECASE)
self.longname = longname
self.shortname = shortname
self.category = category
self.origin = origin
self.history = history
self.definition = definition
self.isSI = isSI
self.wiki = wiki
self.embed = discord.Embed(title=longname, colour=discord.Colour(0xc800), url=wiki, description=('{}\n\n[For more information, refer WikiPedia.]({})'.format(history, wiki)))
self.embed.set_thumbnail(url="https://cdn.discordapp.com/avatars/405724335525855232/c8c782f4c2de5d221d4beb203829ed9c.webp?size=256")
self.embed.add_field(name="Defenition", value=definition)
self.embed.add_field(name="Long Name", value=longname, inline=True)
self.embed.add_field(name="Abbreviation", value=shortname, inline=True)
self.embed.add_field(name="Unit category", value=category, inline=True)
self.embed.add_field(name="Origin", value=origin, inline=True)
self.embed.add_field(name="SI-Unit", value=isSI, inline=True)
# This information 'unitpedia' database needs expansion! Please help by putting information from WikiPedia in here for units not already here!
class InformationArticles:
articles = []
#metre
articles.append(InformationArticle( "(k(ilo)?|c(enti)?|m(illi)?)?m(eters?|etres?)?", "Meter", "m", "Distance", "France, 1789", """In the aftermath of the French Revolution (1789), the traditional units of measure used in the Ancien Régime were replaced. The livre monetary unit was replaced by the decimal franc, and a new unit of length was introduced which became known as the metre.""", """Length of the path travelled by light in a vacuum in 1⁄299792458 of a second.""", "Yes", "https://en.wikipedia.org/wiki/Metre"))
#foot
articles.append(InformationArticle( "f(oo|ee)?t|'|′", "Foot", "ft", "Distance", "Unknown and/or uncertain.", """Historically the human body has been used to provide the basis for units of length. The foot of a white male is typically about 15.3% of his height, giving a person of 160 cm (5 ft 3 in) a foot of 245 mm and one of 180 cm (5 ft 11 in) a foot of 275 mm.""", """Defined by international agreement as equivalent to 0.3048 meters exactly.""", "No", "https://en.wikipedia.org/wiki/Foot_(unit)"))
#mile
articles.append(InformationArticle( "mi(les?)?", "Mile", "mi", "Distance", "Unknown and/or uncertain.", """The mile was established as part of the 1959 international yard and pound agreement reached by the United States, the United Kingdom, Canada, Australia, New Zealand, and South Africa, which resolved small but measurable differences that had arisen from separate physical standards each country had maintained for the yard.""", """The international mile is precisely equal to 1.609344 km (or 25146/15625 km as a fraction).""", "No", "https://en.wikipedia.org/wiki/Mile"))
#litre
articles.append(InformationArticle( "(k(ilo)?|he(k|c)t(a|o)|c(enti)?|m(illi)?)?L((iter|itre|tr)s?)?", "Litre", "L", "Volume", "France, 1795", "The litre was introduced in France in 1795 as one of the new \"republican units of measurement\" and defined as one cubic decimetre. One litre of liquid water has a mass of almost exactly one kilogram, due to the gram being defined in 1795 as one cubic centimetre of water at the temperature of melting ice.", "A litre is defined as a special name for a cubic decimetre or 10 centimetres × 10 centimetres × 10 centimetres, (1 L ≡ 1 dm³ ≡ 1000 cm³).", "Derived from an SI unit", "https://en.wikipedia.org/wiki/Litre"))
#degrees celcius
articles.append(InformationArticle( "(°|º|degrees?)? ?(celcius|centigrade|c|science)", "Celcius Scale", "°C", "Temperature", "Sweden and France, 1742 - 1744", "In 1742, Swedish astronomer Anders Celsius (1701–1744) created a temperature scale which was the reverse of the scale now known by the name \"Celsius\": 0 represented the boiling point of water, while 100 represented the freezing point of water. In 1743, the Lyonnais physicist Jean-Pierre Christin was working independently of Celsius, and developed a scale where zero represented the freezing point of water and 100 represented the boiling point of water. In 1744, coincident with the death of Anders Celsius, the Swedish botanist Carl Linnaeus (1707–1778) reversed Celsius's scale.", "The Celsius scale was based on 0 °C for the freezing point of water and 100 °C for the boiling point of water at 1 atm pressure.", "Derived from an SI unit", "https://en.wikipedia.org/wiki/Celsius"))
#degrees fahrenheit
articles.append(InformationArticle( "((°|º|deg(ree)?s?) ?)?(fahrenheit|freedom|f)", "Fahrenheit scale", "°F", "Temperature", "Germany, 1724", "Fahrenheit proposed his temperature scale in 1724, basing it on two reference points of temperature. In his initial scale (which is not the final Fahrenheit scale), the zero point was determined by placing the thermometer in a mixture \"of ice, of water, and of ammonium chloride (salis Armoniaci) or even of sea salt\". This combination forms a eutectic system which stabilizes its temperature automatically: 0 °F was defined to be that stable temperature. The second point, 96 degrees, was approximately the human body's temperature (sanguine hominis sani, the blood of a healthy man).", "On the Fahrenheit scale, the freezing point of water is 32 degrees Fahrenheit (°F) and the boiling point is 212 °F (at standard atmospheric pressure). A degree on the Fahrenheit scale is 1⁄180 of the interval between the freezing point and the boiling point.", "No", "https://en.wikipedia.org/wiki/Fahrenheit"))
#degrees kelvin
articles.append(InformationArticle( "((°|º|deg(ree)?s?) ?)?(kelvin|k)", "Kelvin scale", "K", "Temperature", "Great Britain, 1848", "In 1848, William Thomson, who later was made Lord Kelvin, wrote in his paper, On an Absolute Thermometric Scale, of the need for a scale whereby \"infinite cold\" (absolute zero) was the scale's null point, and which used the degree Celsius for its unit increment. Kelvin calculated that absolute zero was equivalent to −273 °C on the air thermometers of the time. This absolute scale is known today as the Kelvin thermodynamic temperature scale.", "Until 2018, the kelvin was defined as the fraction 1/273.16 of the thermodynamic temperature of the triple point of water (0.01 °C or 32.018 °F). In other words, it was defined such that the triple point of water is exactly 273.16 K. On 16 November 2018, a new definition was adopted, in terms of a fixed value of the Boltzmann constant. For legal metrology purposes, the new definition will officially come into force on 20 May 2019.", "Yes", "https://en.wikipedia.org/wiki/Kelvin"))
#kilogram
articles.append(InformationArticle( "((kilo)? ?gram(me)?$)|(kilo$)|(kg$)", "kilogramme or kilogram", "kg", "Mass", "France, 1799", "The kilogram was originally defined in 1795 as the mass of a litre of water. This was a convenient definition, but hard to replicate precisely. In 1799, the Kilogramme des Archives, a platinum artefact, replaced it as a standard mass sample. Later, the International Prototype of the Kilogram (IPK) became the standard of the unit of mass for the metric system, and remained so until May 20, 2019. In spite of best efforts to maintain it, the IPK diverged from its replicas by approximately 50 micrograms since their manufacture late in the 19th century. This led to efforts to develop measurement technology precise enough to allow replacing the kilogram artefact with a definition based directly on physical fundamental constants. This was achieved in 2018, with a definition in terms of the Planck constant.", "The kilogram is defined by taking the fixed numerical value of the Planck constant h to be 6.62607015×10^(−34) when expressed in the unit J⋅s, which is equal to kg⋅m2⋅s^(−1), where the metre and the second are defined in terms of c and ΔνCs.", "Yes", "https://en.wikipedia.org/wiki/kilogram"))
# TODO: Add more units...
# example:
# articles.append(InformationArticle( "regex", "Long name", "abbreviation", "type of unit", "origin (country, year)", "History of the unit.", "The way this unit is defined", "Is this an SI unit? 'Yes', 'No' or 'Derived from SI'", "Link to the wikipedia page."))